|
22 | 22 | deploy: |
23 | 23 | needs: build-and-test |
24 | 24 | runs-on: ubuntu-latest |
25 | | - permissions: |
26 | | - contents: write # Required for saving deployment |
27 | 25 | 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' |
28 | 34 | steps: |
29 | 35 | - name: Checkout |
30 | 36 | uses: actions/checkout@v4 |
@@ -68,12 +74,35 @@ jobs: |
68 | 74 | ADMIN_PRIVATE_KEY: ${{ secrets.ADMIN_PRIVATE_KEY }} |
69 | 75 | run: npx hardhat run scripts/tools/update-config.ts --network ${{ inputs.network }} |
70 | 76 |
|
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' |
73 | 79 | uses: stefanzweifel/git-auto-commit-action@v5 |
74 | 80 | 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