-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve MAlonzo code generation workflow (#530)
- Create an orphan branch (`MAlonzo-code`) for the generated code - When opening a PR for a feature branch, create a separate branch based on the `MAlonzo-code` branch which will contain newly generated code from the feature branch - Once the PR is successfully merged, the branch based on `MAlonzo-code` gets squash merged into `MAlonzo-code` and deleted Esentially, the above setup attempts to replicate the git feature branch workflow for the generated code, where the `MAlonzo-code` branch corresponds to the `main` / `master` branch.
- Loading branch information
1 parent
afbecee
commit 65c5145
Showing
2 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,24 @@ on: | |
permissions: | ||
contents: write | ||
|
||
env: | ||
MAlonzo_branch: ${{ github.event.pull_request.head.ref }}-MAlonzo | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: MAlonzo-code | ||
|
||
- name: Create branch ${{ env.MAlonzo_branch }} for generated code | ||
if: github.event_name == 'pull_request' && github.event.action == 'opened' | ||
run: | | ||
git checkout -b ${{ env.MAlonzo_branch }} origin/MAlonzo-code | ||
git push origin ${{ env.MAlonzo_branch }} | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: cachix/install-nix-action@v20 | ||
|
@@ -65,11 +78,14 @@ jobs: | |
echo "** Generated Haskell files:"; find -L docs/ -name '*.hs' | ||
OUT_DIR=../docs/ make staticWebsite | ||
- name: Configure git | ||
run: | | ||
git config user.name 'github-actions[bot]' | ||
git config user.email 'github-actions[bot]@users.noreply.github.com' | ||
- name: Add files | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
git config user.name 'github-actions[bot]' | ||
git config user.email 'github-actions[bot]@users.noreply.github.com' | ||
git add -f docs/ | ||
git commit -m "Updated for ${{ github.sha }}" | ||
|
@@ -82,20 +98,21 @@ jobs: | |
force: true | ||
directory: . | ||
|
||
- name: Commit haskell package | ||
if: github.ref == 'refs/heads/master' | ||
- name: Commit generated code at ${{ env.MAlonzo_branch }} | ||
if: github.ref != 'refs/heads/master' | ||
run: | | ||
nix-build -A ledger.hsSrc -j1 -o outputs/ledgerSrc | ||
nix-build -A ledger.hsSrc -j1 -o outputs/MAlonzo | ||
git stash push | ||
rsync -r --exclude={'**/nix-support','**/lib'} outputs/ledgerSrc/* ledgerSrc/ | ||
git add -f ledgerSrc | ||
git commit -m "Updated for ${{ github.sha }}" | ||
git fetch origin ${{ env.MAlonzo_branch }} --depth 1 | ||
git checkout ${{ env.MAlonzo_branch }} | ||
rsync -r --exclude={'**/nix-support','**/lib'} outputs/MAlonzo/haskell/Ledger/* generated/ | ||
git add -f generated && git commit -m "Generate code for ${{ github.sha }}" || echo "Everything is up-to-date." | ||
- name: Push haskell package | ||
if: github.ref == 'refs/heads/master' | ||
- name: Push ${{ env.MAlonzo_branch }} | ||
if: github.ref != 'refs/heads/master' | ||
uses: ad-m/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: haskell-package | ||
force: true | ||
branch: ${{ env.MAlonzo_branch }} | ||
force: false | ||
directory: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Formal Ledger Specs - PR Merged | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
types: | ||
- closed | ||
|
||
permissions: | ||
contents: write | ||
|
||
env: | ||
MAlonzo_branch: ${{ github.event.pull_request.head.ref }}-MAlonzo | ||
|
||
jobs: | ||
pr-merged: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: MAlonzo-code | ||
- name: Merge ${{ env.MAlonzo_branch }} into MAlonzo-code | ||
if: github.event.pull_request.merged | ||
run: | | ||
git config user.name 'github-actions[bot]' | ||
git config user.email 'github-actions[bot]@users.noreply.github.com' | ||
# GitHub Actions fetches shallow copies of remote branches | ||
# which might not be ideal when rebasing, hence use `--unshallow`. | ||
git fetch --unshallow origin ${{ env.MAlonzo_branch }} | ||
git checkout ${{ env.MAlonzo_branch }} | ||
# During `git rebase` 'ours' and 'theirs' are flipped | ||
# so what we do here is that we keep the changes from ${{ env.MAlonzo_branch }}. | ||
git rebase -X theirs origin/MAlonzo-code | ||
git checkout MAlonzo-code | ||
git merge --squash ${{ env.MAlonzo_branch }} | ||
git commit -m "Generate code for GH-${{ github.event.pull_request.number }}" || echo "Everything is up-to-date." | ||
- name: Push MAlonzo-code | ||
if: github.event.pull_request.merged | ||
uses: ad-m/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: MAlonzo-code | ||
force: false | ||
directory: . | ||
|
||
- name: Delete ${{ env.MAlonzo_branch }} branch | ||
if: github.event.pull_request.merged | ||
uses: dawidd6/action-delete-branch@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
branches: ${{ env.MAlonzo_branch }} |