Skip to content

Commit

Permalink
Add deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
thommythomaso committed Feb 26, 2024
1 parent fa139d0 commit 2226e80
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 4 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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 <[email protected]>

name: deploy

on: [ push, pull_request, workflow_dispatch ]

jobs:

deploy:
needs: analyze build doc gitlab-ci lint
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
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: python3 util/deploy.py
9 changes: 5 additions & 4 deletions target/rtl/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Bender.yml
include
*.sv
*.hjson
# Deactivated by deploy.py
# Bender.yml
# include
# *.sv
# *.hjson
73 changes: 73 additions & 0 deletions util/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/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 <[email protected]>

"""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'
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]
current_hash = os.popen(GET_COMMIT_ID_CMD).read().split('\n')[0]
current_msg = '\n'.join(os.popen(GET_COMMIT_MSG_CMD).read().split('\n')[:-1])

# create target branch
deploy_branch = f'__deploy__{current_branch}'
last_deploy_hash = os.popen(f'{CHECK_BRANCH_CMD} {deploy_branch}').read()
deploy_msg = f'{current_msg}\n-----\n\nDeployed from {current_hash}'

# 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(0.5)

# 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}')

0 comments on commit 2226e80

Please sign in to comment.