Skip to content

Commit 9d5ff50

Browse files
authored
chore: Push artifacts using PRs on the protected branch (#285)
1 parent 9b06da2 commit 9d5ff50

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ jobs:
2222
deploy:
2323
needs: build-and-test
2424
runs-on: ubuntu-latest
25-
permissions:
26-
contents: write # Required for saving deployment
2725
environment: ${{ inputs.network }} # Use the selected environment
26+
permissions:
27+
contents: write # Required to commit artifacts.
28+
pull-requests: write # Required to create pull requests.
29+
env:
30+
# For commit action
31+
COMMIT_MESSAGE: 'chore: Save artifacts - ${{ inputs.network }} (runId:${{ github.run_id }})'
32+
GHA_BOT_NAME: 'GitHub Actions Bot'
33+
GHA_BOT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
2834
steps:
2935
- name: Checkout
3036
uses: actions/checkout@v4
@@ -68,12 +74,35 @@ jobs:
6874
ADMIN_PRIVATE_KEY: ${{ secrets.ADMIN_PRIVATE_KEY }}
6975
run: npx hardhat run scripts/tools/update-config.ts --network ${{ inputs.network }}
7076

71-
- name: Save deployment artifacts and updated config
72-
if: inputs.network != 'hardhat'
77+
- name: Push artifacts to the current branch
78+
if: inputs.network != 'hardhat' && github.ref != 'refs/heads/main'
7379
uses: stefanzweifel/git-auto-commit-action@v5
7480
with:
75-
commit_message: 'chore: Save deployment artifacts for ${{ inputs.network }} (run_id: ${{ github.run_id }})'
76-
file_pattern: 'deployments/${{ inputs.network }}/* config/config.json'
77-
commit_user_name: 'GitHub Actions Bot'
78-
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
79-
commit_author: 'GitHub Actions Bot <github-actions[bot]@users.noreply.github.com>'
81+
file_pattern: |
82+
config/config.json
83+
deployments/${{ inputs.network }}/
84+
commit_message: ${{ env.COMMIT_MESSAGE }}
85+
commit_user_name: ${{ env.GHA_BOT_NAME }}
86+
commit_user_email: ${{ env.GHA_BOT_EMAIL }}
87+
commit_author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
88+
89+
# Since the `main` branch is protected, create a PR to push artifacts.
90+
- name: Push artifacts through a pull request
91+
if: inputs.network != 'hardhat' && github.ref == 'refs/heads/main'
92+
uses: peter-evans/create-pull-request@v7
93+
with:
94+
add-paths: |
95+
config/config.json
96+
deployments/${{ inputs.network }}/
97+
commit-message: ${{ env.COMMIT_MESSAGE }}
98+
committer: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
99+
author: '${{ env.GHA_BOT_NAME }} <${{ env.GHA_BOT_EMAIL }}>'
100+
branch: chore/save-artifacts-${{ inputs.network }}
101+
title: ${{ env.COMMIT_MESSAGE }}
102+
draft: true
103+
body: |
104+
🤖 This is an automated pull request to save deployment artifacts.
105+
* Network: `${{ inputs.network }}`
106+
* Job: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
107+
108+
**Note**: Verify deployment before merging this PR.

0 commit comments

Comments
 (0)