From 0a2fceded496c83838b9fd95b2899d15a1ae3976 Mon Sep 17 00:00:00 2001 From: Eren Dogan Date: Sun, 12 Feb 2023 16:37:30 -0800 Subject: [PATCH] Add new workflows --- .github/workflows/README.md | 69 +++++++++++++++++++++++ .github/workflows/deploy.yml | 3 +- .github/workflows/{ci.yml => regress.yml} | 32 +++++++++-- .github/workflows/sync.yml | 25 ++++++++ .github/workflows/version.yml | 44 +++++++++++++++ 5 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/README.md rename .github/workflows/{ci.yml => regress.yml} (55%) create mode 100644 .github/workflows/sync.yml create mode 100644 .github/workflows/version.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 00000000..7648a890 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,69 @@ +# How do the workflows work? + +1. When there is a push to the private repo's 'dev' branch (private/dev), +`regress` workflow runs the regression tests. + +1. If `regress` workflow fails on 'private/dev', `sync` workflow gets triggered +and it pushes the latest changes to the public repo's 'dev' branch (public/dev). +After this push, `regress` workflow will also run on 'public/dev'. + +1. If `regress` workflow successfully passes on 'private/dev', `version` +workflow gets triggered. It creates a new version commit and tag, and pushes to +'private/dev', 'public/dev', 'public/stable'. + +1. When there is a push with new version to the 'public/stable' branch, `deploy` +workflow runs. It deploys the PyPI package of OpenRAM. + +1. If there is a pull request on either repo, `regress` workflow runs on that +pull request. + +1. If there is a push to 'public/dev', `regress` workflow runs (it also happens +when pull requests are merged). + +1. If `regress` workflow successfully passes on 'public/dev', `version` +workflow gets triggered. It creates a new version commit and tag, and pushes to +'private/dev', 'public/dev', and 'public/stable'. + + + +## Important Notes + +1. Workflows understand that the latest commit has a new version with the +following commit message syntax. + + ``` + Bump version: + ``` + + Automatically generated version commit have the following syntax: + + ``` + Bump version: a.b.c -> a.b.d + ``` + +1. `version` workflow only increments the right-most version digit. Other digits +in the version number must be updated manually following the syntax above. + +1. `regress` workflow doesn't run if the push has a new version. We assume that +this commit was automatically generated after a previous commit passed `regress` +workflow or was manually generated with caution. + +1. `regress` workflow doesn't run on branches named 'stable'. + +1. `deploy` workflow only runs on branches named 'stable'. + +1. `version` workflow is only triggered from branches named 'dev' if they pass +`regress` workflow. + +1. `sync` workflow only runs on the private repo. + +1. Pull requests merged on to 'public/dev' will also trigger `regress` and it +can create a new version. + +1. Merging pull requests that don't pass `regress` workflow on the public repo +should be avoided since it won't update the private repo automatically. To +prevent merging by mistake, the dev branch can be protected in the GitHub +settings. + +1. Merging pull requests on the private repo should be safe in any case. + diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1ee4c0a8..48556fa7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,10 +3,9 @@ on: push: branches: - stable - tags: - - 'v*.*.*' jobs: deploy_pip: + if: ${{ startsWith(github.event.head_commit.message, 'Bump version:') }} runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.github/workflows/ci.yml b/.github/workflows/regress.yml similarity index 55% rename from .github/workflows/ci.yml rename to .github/workflows/regress.yml index 9fa83326..e9cda14a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/regress.yml @@ -1,10 +1,16 @@ -name: ci +name: regress on: push: - branches: - - '!stable' + branches-ignore: + - stable + pull_request: + branches-ignore: + - stable jobs: - regress: + # All tests should be run from this job. + regression_test: + # This job runs on pull requests or any push that doesn't have a new version + if: ${{ github.event_name == 'pull_request' || startsWith(github.event.head_commit.message, 'Bump version:') == false }} runs-on: self-hosted steps: - name: Checkout code @@ -42,5 +48,19 @@ jobs: if: ${{ failure() }} uses: actions/upload-artifact@v2 with: - name: Regress Archives - path: ${{ github.workspace }}/compiler/tests/results/* + name: Regress Archives + path: ${{ github.workspace }}/compiler/tests/results/* + # This job triggers sync.yml workflow + sync_trigger: + if: ${{ always() && github.event_name == 'push' && github.ref_name == 'dev' && github.repository == 'VLSIDA/PrivateRAM' && needs.regression_test.result == 'failure' }} + needs: regression_test + uses: ./.github/workflows/sync.yml + secrets: + ACCESS_TOKEN_GITHUB: ${{ secrets.WORKFLOW_ACCESS_TOKEN }} + # This job triggers version.yml workflow + version_trigger: + if: ${{ github.event_name == 'push' && github.ref_name == 'dev' }} + needs: regression_test + uses: ./.github/workflows/version.yml + secrets: + ACCESS_TOKEN_GITHUB: ${{ secrets.WORKFLOW_ACCESS_TOKEN }} diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 00000000..7e374d50 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,25 @@ +name: sync +on: + workflow_call: + secrets: + WORKFLOW_ACCESS_TOKEN: + required: true +jobs: + sync_dev: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.WORKFLOW_ACCESS_TOKEN }} + - name: Synchronize OpenRAM repo + run: | + # Configure pusher account + git config --global user.name "mrg" + git config --global user.email "mrg@ucsc.edu" + # Add remote repo + git remote add public-repo https://${{ secrets.WORKFLOW_ACCESS_TOKEN }}@github.com/VLSIDA/OpenRAM.git + git pull public-repo dev + # Push the latest changes + git push -u public-repo HEAD:dev diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 00000000..18271019 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,44 @@ +name: version +on: + workflow_call: + secrets: + WORKFLOW_ACCESS_TOKEN: + required: true +jobs: + make_version: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.WORKFLOW_ACCESS_TOKEN }} + - name: Configure git + run: | + # Configure the committer + git config --global user.name "mrg" + git config --global user.email "mrg@ucsc.edu" + # Set remote repos + git remote add private-repo https://${{ secrets.WORKFLOW_ACCESS_TOKEN }}@github.com/VLSIDA/PrivateRAM.git + git remote add public-repo https://${{ secrets.WORKFLOW_ACCESS_TOKEN }}@github.com/VLSIDA/OpenRAM.git + - name: Make new version number + run: | + # Read the current version number + export CURRENT_VERSION="$(cat VERSION)" + # Increment the version number + export NEXT_VERSION="$(echo ${CURRENT_VERSION} | awk -F. -v OFS=. '{$NF += 1 ; print}')" + echo "${NEXT_VERSION}" > VERSION + # Commit the change and tag the commit + git commit -a -m "Bump version: ${CURRENT_VERSION} -> ${NEXT_VERSION}" + git tag "v${NEXT_VERSION}" HEAD + - name: Push changes + run: | + # Push to private/dev + git pull private-repo dev + git push private-repo HEAD:dev --tags + # Push to public/dev + git pull public-repo dev + git push public-repo HEAD:dev --tags + # Push to public/stable + git pull public-repo stable + git push public-repo HEAD:stable --tags