Skip to content

Commit c246169

Browse files
authored
chore: Push artifacts using PRs on the protected branch (#110)
1 parent 627c937 commit c246169

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

.github/workflows/deploy.yml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ jobs:
2828
deploy:
2929
needs: build-and-test
3030
runs-on: ubuntu-latest
31+
environment: ${{ inputs.network }}
32+
permissions:
33+
contents: write # Required to commit artifacts.
34+
pull-requests: write # Required to create pull requests.
3135
env:
3236
CI: true
33-
permissions:
34-
contents: write # Required to commit deployment files.
35-
environment: ${{ inputs.network }}
37+
# For commit action
38+
COMMIT_MESSAGE: 'chore: Save artifacts - ${{ inputs.network }} (runId:${{ github.run_id }})'
39+
GHA_BOT_NAME: 'GitHub Actions Bot'
40+
GHA_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
3641
steps:
3742
- uses: actions/checkout@v4
3843
with:
@@ -73,16 +78,39 @@ jobs:
7378
run: |
7479
make deploy-crosschain-token-and-bridge
7580
76-
- name: Save deployment artifacts
77-
if: inputs.network != 'anvil'
81+
- name: Push artifacts to the current branch
82+
if: inputs.network != 'anvil' && github.ref != 'refs/heads/main'
7883
uses: stefanzweifel/git-auto-commit-action@v5
7984
with:
80-
commit_message: 'chore: save deployment artifacts for ${{ inputs.network }} (Github run_id: ${{ github.run_id }})'
81-
file_pattern: 'config/config.json broadcast/'
82-
commit_user_name: 'GitHub Actions Bot'
83-
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
84-
commit_author: 'GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>'
85-
85+
file_pattern: |
86+
config/config.json
87+
broadcast/
88+
commit_message: ${{ env.COMMIT_MESSAGE }}
89+
commit_user_name: ${{ env.GHA_BOT_NAME }}
90+
commit_user_email: ${{ env.GHA_BOT_EMAIL }}
91+
commit_author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
92+
93+
# Since the `main` branch is protected, create a PR to push artifacts.
94+
- name: Push artifacts through a pull request
95+
if: inputs.network != 'anvil' && github.ref == 'refs/heads/main'
96+
uses: peter-evans/create-pull-request@v7
97+
with:
98+
add-paths: |
99+
config/config.json
100+
broadcast/
101+
commit-message: ${{ env.COMMIT_MESSAGE }}
102+
committer: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
103+
author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
104+
branch: chore/save-artifacts-${{ inputs.network }}
105+
title: ${{ env.COMMIT_MESSAGE }}
106+
draft: true
107+
body: |
108+
🤖 This is an automated pull request to save deployment artifacts.
109+
* Network: `${{ inputs.network }}`
110+
* Job: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
111+
112+
**Note**: Verify deployment before merging this PR.
113+
86114
- name: Verify contracts
87115
if: inputs.network != 'anvil'
88116
continue-on-error: true

0 commit comments

Comments
 (0)