Skip to content

Commit

Permalink
CI: Add deploy script to check-in generated iDMA configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
thommythomaso committed Mar 11, 2024
1 parent 5f7d089 commit 24770bc
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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:
branches-ignore:
- '__deploy__**'

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 "[email protected]"
git config user.name "github-ci"
git fetch --all
python3 util/deploy.py
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ init:
idma:
stage: idma
needs: [ init ]
except:
- /^__deploy__.*$/
trigger:
include:
- artifact: nonfree/ci/ci.yml
Expand Down
64 changes: 64 additions & 0 deletions util/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/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
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_TAG_CMD = 'git checkout -b'
GIT_COMMIT_CMD = 'git commit -m'
GIT_PUSH_CMD = 'git push'

# Repo configuration
ORIGIN = 'origin'

# 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_hash[0:7]}__{current_branch}'
print(f'Deploy branch: {deploy_branch}\n\n')
deploy_msg = f'{current_msg}\n-----\n\nDeployed from {current_hash}'
print(f'Deploy commit message:\n{deploy_msg}')

# create new deploy branch
os.popen(f'{GIT_CHECKOUT_TAG_CMD} {deploy_branch} {current_branch}')
time.sleep(2)

# 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 24770bc

Please sign in to comment.