|
8 | 8 | jobs:
|
9 | 9 | update-fpm:
|
10 | 10 | runs-on: ubuntu-latest
|
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
11 | 14 |
|
12 | 15 | steps:
|
13 | 16 | - name: Checkout repository
|
@@ -48,18 +51,103 @@ jobs:
|
48 | 51 | echo "SHA256=${SHA256}" >> "$GITHUB_ENV"
|
49 | 52 | echo "New SHA256: ${SHA256}"
|
50 | 53 |
|
| 54 | + - name: Create branch for update |
| 55 | + if: env.UPDATE_NEEDED == 'true' |
| 56 | + run: | |
| 57 | + BRANCH_NAME="auto-update-fpm-${LATEST_VERSION}" |
| 58 | + git checkout -b "${BRANCH_NAME}" |
| 59 | + echo "BRANCH_NAME=${BRANCH_NAME}" >> "$GITHUB_ENV" |
| 60 | +
|
51 | 61 | - name: Update formula
|
52 | 62 | if: env.UPDATE_NEEDED == 'true'
|
53 | 63 | run: |
|
54 | 64 | sed -i "s|url \".*\"|url \"https://github.com/fortran-lang/fpm/releases/download/${LATEST_VERSION_V}/fpm-${LATEST_VERSION}.zip\"|" Formula/fpm.rb
|
55 | 65 | sed -i "s|sha256 \".*\"|sha256 \"${SHA256}\"|" Formula/fpm.rb
|
56 | 66 |
|
57 |
| - - name: Commit and push changes |
| 67 | + - name: Commit changes |
58 | 68 | if: env.UPDATE_NEEDED == 'true'
|
59 | 69 | run: |
|
60 | 70 | git config --global user.name "GitHub Actions"
|
61 | 71 | git config --global user.email "[email protected]"
|
62 | 72 | git add Formula/fpm.rb
|
63 | 73 | git commit -m "Update fpm to ${LATEST_VERSION}"
|
64 |
| - git push |
65 | 74 |
|
| 75 | + - name: Push changes to branch |
| 76 | + if: env.UPDATE_NEEDED == 'true' |
| 77 | + run: | |
| 78 | + git push origin "${BRANCH_NAME}" |
| 79 | +
|
| 80 | + - name: Create Pull Request |
| 81 | + if: env.UPDATE_NEEDED == 'true' |
| 82 | + id: create-pr |
| 83 | + uses: peter-evans/create-pull-request@v5 |
| 84 | + with: |
| 85 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + commit-message: "Update fpm to ${{ env.LATEST_VERSION }}" |
| 87 | + title: "Update fpm to ${{ env.LATEST_VERSION }}" |
| 88 | + body: | |
| 89 | + This PR automatically updates the fpm formula to version ${{ env.LATEST_VERSION }}. |
| 90 | + |
| 91 | + **Changes:** |
| 92 | + - Updated URL to ${{ env.LATEST_VERSION_V }} release |
| 93 | + - Updated SHA256 to match the new release |
| 94 | + |
| 95 | + This PR was created automatically by GitHub Actions. |
| 96 | + branch: ${{ env.BRANCH_NAME }} |
| 97 | + base: main |
| 98 | + labels: | |
| 99 | + automated-pr |
| 100 | + version-bump |
| 101 | +
|
| 102 | + # Wait for test-bot CI to complete |
| 103 | + - name: Wait for test-bot to complete |
| 104 | + if: env.UPDATE_NEEDED == 'true' && steps.create-pr.outputs.pull-request-number |
| 105 | + run: | |
| 106 | + # Wait for CI to start and finish (maximum 30 minutes) |
| 107 | + echo "Waiting for test-bot workflow to complete..." |
| 108 | + PR_NUMBER=${{ steps.create-pr.outputs.pull-request-number }} |
| 109 | + timeout=1800 # 30 minutes in seconds |
| 110 | + interval=60 # Check every minute |
| 111 | + elapsed=0 |
| 112 | + |
| 113 | + while [ $elapsed -lt $timeout ]; do |
| 114 | + # Check if test-bot workflow has completed |
| 115 | + STATUS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 116 | + "https://api.github.com/repos/${{ github.repository }}/actions/runs?status=completed&event=pull_request&head_sha=$(git rev-parse HEAD)") |
| 117 | + |
| 118 | + COMPLETED=$(echo "$STATUS" | jq -r '.workflow_runs[] | select(.name == "brew test-bot") | .status') |
| 119 | + |
| 120 | + if [ "$COMPLETED" = "completed" ]; then |
| 121 | + CONCLUSION=$(echo "$STATUS" | jq -r '.workflow_runs[] | select(.name == "brew test-bot") | .conclusion') |
| 122 | + if [ "$CONCLUSION" = "success" ]; then |
| 123 | + echo "test-bot workflow completed successfully!" |
| 124 | + break |
| 125 | + elif [ "$CONCLUSION" = "failure" ]; then |
| 126 | + echo "test-bot workflow failed!" |
| 127 | + exit 1 |
| 128 | + fi |
| 129 | + fi |
| 130 | + |
| 131 | + sleep $interval |
| 132 | + elapsed=$((elapsed + interval)) |
| 133 | + echo "Still waiting... ($elapsed seconds elapsed)" |
| 134 | + done |
| 135 | + |
| 136 | + if [ $elapsed -ge $timeout ]; then |
| 137 | + echo "Timeout waiting for test-bot workflow to complete" |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | +
|
| 141 | + # Add label to trigger pr-pull workflow |
| 142 | + - name: Add pr-pull label |
| 143 | + if: env.UPDATE_NEEDED == 'true' && steps.create-pr.outputs.pull-request-number |
| 144 | + uses: actions/github-script@v6 |
| 145 | + with: |
| 146 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 147 | + script: | |
| 148 | + github.rest.issues.addLabels({ |
| 149 | + owner: context.repo.owner, |
| 150 | + repo: context.repo.repo, |
| 151 | + issue_number: ${{ steps.create-pr.outputs.pull-request-number }}, |
| 152 | + labels: ['pr-pull'] |
| 153 | + }) |
0 commit comments