diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..9e934d53 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,53 @@ +# Copyright 2024 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +# Authors: +# - Thomas Benz + +name: deploy + +on: [ push, pull_request, workflow_dispatch ] + +jobs: + + deploy: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + - + name: Python Requirements + run: pip install -r requirements.txt + - + name: Install Bender + uses: pulp-platform/pulp-actions/bender-install@v2 + with: + version: 0.27.3 + - + name: Install Morty + run: | + curl --proto '=https' --tlsv1.2 -sLO https://github.com/pulp-platform/morty/releases/download/v0.9.0/morty-ubuntu.22.04-x86_64.tar.gz + tar -xvf morty-ubuntu.22.04-x86_64.tar.gz morty + rm -f morty-ubuntu.22.04-x86_64.tar.gz + chmod 777 morty + echo "PATH=.:$PATH" >> ${GITHUB_ENV} + - + name: Build hardware + run: make -B idma_hw_all + - + name: Deploy generated files + run: | + git config user.email "github-ci@iis.ee.ethz.ch" + git config user.name "github-ci" + git fetch --all + python3 util/deploy.py diff --git a/util/deploy.py b/util/deploy.py new file mode 100644 index 00000000..ddc797b1 --- /dev/null +++ b/util/deploy.py @@ -0,0 +1,79 @@ +#!/usr/env python3 +# Copyright 2024 ETH Zurich and University of Bologna. +# Solderpad Hardware License, Version 0.51, see LICENSE for details. +# SPDX-License-Identifier: SHL-0.51 + +# Authors: +# - Thomas Benz + +"""Deploy script run by ci. Creates a deploy branch which includes generated files.""" +import os +import time + +# Git command fragments +CHECK_BRANCH_CMD = 'git rev-parse --verify' +GET_BRANCH_CMD = '''git for-each-ref --format='%(objectname) %(refname:short)' refs/heads |\ + awk "/^$(git rev-parse HEAD)/ {print \\$2}"''' +GET_COMMIT_ID_CMD = 'git rev-parse HEAD' +GET_COMMIT_MSG_CMD = 'git log -1 --pretty=%B' +GIT_ADD_ALL_CMD = 'git add .' +GIT_CHECKOUT_CMD = 'git checkout' +GIT_CHECKOUT_TAG_CMD = 'git checkout -b' +GIT_COMMIT_CMD = 'git commit -m' +GIT_MERGE_SQUASH_CMD = 'git merge --squash -s ours' +GIT_PUSH_CMD = 'git push' + +# Repo configuration +ORIGIN = 'origin' +ROOT_MAIN_TAG = 'v0.6.0-beta' + +# Comment added to gitignore +GITIGNORE_COMMENT = '# Deactivated by deploy.py' + +# get current branch info +current_branch = os.popen(GET_BRANCH_CMD).read().split('\n')[0] +print(f'Current branch: {current_branch}') +current_hash = os.popen(GET_COMMIT_ID_CMD).read().split('\n')[0] +print(f'Current hash: {current_hash}') +current_msg = '\n'.join(os.popen(GET_COMMIT_MSG_CMD).read().split('\n')[:-1]) +print(f'Current commit message: \n{current_msg}') + +# create target branch +deploy_branch = f'__deploy__{current_branch}' +print(f'Deploy branch: {deploy_branch}\n\n') +last_deploy_hash = os.popen(f'{CHECK_BRANCH_CMD} {ORIGIN}/{deploy_branch}').read() +print(f'Last deploy hash: {last_deploy_hash} (empty if on deploy branch present)') +deploy_msg = f'{current_msg}\n-----\n\nDeployed from {current_hash}' +print(f'Deploy commit message:\n{deploy_msg}') + +# spawn or switch to deploy branch +if last_deploy_hash == '': + # create new deploy branch + os.popen(f'{GIT_CHECKOUT_TAG_CMD} {deploy_branch} {ROOT_MAIN_TAG}') +else: + # deploy branch exists + os.popen(f'{GIT_CHECKOUT_CMD} {deploy_branch}') +time.sleep(2) + +# merge feature into deploy branch +os.popen(f'{GIT_MERGE_SQUASH_CMD} {ORIGIN}/{current_branch}') +time.sleep(0.5) + +# selectively deactivate gitignore to check in generated files +with open('target/rtl/.gitignore', 'r', encoding='utf-8') as f: + content = f.read().split('\n')[:-1] + +if content[0] != GITIGNORE_COMMENT: + with open('target/rtl/.gitignore', 'w', encoding='utf-8') as f: + f.write(f'{GITIGNORE_COMMENT}\n') + for line in content: + f.write(f'# {line}\n') + +# add and commit files +os.popen(GIT_ADD_ALL_CMD) +time.sleep(0.5) +os.popen(f'{GIT_COMMIT_CMD} "{deploy_msg}"') +time.sleep(0.5) + +# push state to origin +os.popen(f'{GIT_PUSH_CMD} {ORIGIN} {deploy_branch}')