Skip to content

Commit 3c25114

Browse files
authored
fpm CI: fix branch generation (#47)
2 parents a441e55 + 61bf5c6 commit 3c25114

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

.github/workflows/fpm-version-update.yml

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
- name: Compare versions
3636
id: check-update
3737
run: |
38-
if [ "${LATEST_VERSION}" != "${CURRENT_VERSION}" ] || [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then
39-
echo "New version available!"
38+
if [ "${{ env.LATEST_VERSION }}" != "${{ env.CURRENT_VERSION }}" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
39+
echo "New version available or manually triggered!"
4040
echo "UPDATE_NEEDED=true" >> "$GITHUB_ENV"
4141
else
4242
echo "UPDATE_NEEDED=false" >> "$GITHUB_ENV"
@@ -47,53 +47,46 @@ jobs:
4747
if: env.UPDATE_NEEDED == 'true'
4848
id: get-sha256
4949
run: |
50-
SHA_URL="https://github.com/fortran-lang/fpm/releases/download/${LATEST_VERSION_V}/fpm-${LATEST_VERSION}.zip.sha256"
50+
SHA_URL="https://github.com/fortran-lang/fpm/releases/download/${{ env.LATEST_VERSION_V }}/fpm-${{ env.LATEST_VERSION }}.zip.sha256"
5151
SHA256="$(curl -sL "${SHA_URL}" | awk '{print $1}')"
5252
echo "SHA256=${SHA256}" >> "$GITHUB_ENV"
5353
echo "New SHA256: ${SHA256}"
5454
5555
- name: Create branch for update
5656
if: env.UPDATE_NEEDED == 'true'
5757
run: |
58-
BRANCH_NAME="auto-update-fpm-${LATEST_VERSION}"
59-
git checkout -b "${BRANCH_NAME}"
58+
BRANCH_NAME="auto-update-fpm-${{ env.LATEST_VERSION }}-$(date +%s)" # Add timestamp to branch name for uniqueness
6059
echo "BRANCH_NAME=${BRANCH_NAME}" >> "$GITHUB_ENV"
6160
6261
- name: Update formula
6362
if: env.UPDATE_NEEDED == 'true'
6463
run: |
65-
sed -i "s|url \".*\"|url \"https://github.com/fortran-lang/fpm/releases/download/${LATEST_VERSION_V}/fpm-${LATEST_VERSION}.zip\"|" Formula/fpm.rb
66-
sed -i "s|sha256 \".*\"|sha256 \"${SHA256}\"|" Formula/fpm.rb
67-
echo "# Formula last updated on $(date +'%Y-%m-%d %H:%M:%S')" >> Formula/fpm.rb
68-
69-
- name: Commit changes
70-
if: env.UPDATE_NEEDED == 'true'
71-
run: |
72-
git config --global user.name "GitHub Actions"
73-
git config --global user.email "[email protected]"
74-
git add Formula/fpm.rb
75-
git status # Check if any files are staged for commit
76-
git commit -m "Update fpm to ${LATEST_VERSION}"
77-
78-
- name: Push changes to branch
64+
TIMESTAMP=$(date +%s)
65+
RUN_ID="${{ github.run_id }}-${{ github.run_number }}"
66+
sed -i "1s/^/# Formula last updated on $(date -u +"%Y-%m-%dT%H:%M:%SZ") (Run: ${RUN_ID})\n/" Formula/fpm.rb
67+
sed -i "s|url \".*\"|url \"https://github.com/fortran-lang/fpm/releases/download/${{ env.LATEST_VERSION_V }}/fpm-${{ env.LATEST_VERSION }}.zip\"|" Formula/fpm.rb
68+
sed -i "s|sha256 \".*\"|sha256 \"${{ env.SHA256 }}\"|" Formula/fpm.rb
69+
70+
- name: Debug - Show changes
7971
if: env.UPDATE_NEEDED == 'true'
8072
run: |
81-
git push origin ${{ env.BRANCH_NAME }}
73+
git diff Formula/fpm.rb || echo "No changes detected in Formula/fpm.rb"
8274
8375
- name: Create Pull Request
8476
if: env.UPDATE_NEEDED == 'true'
8577
id: create-pr
86-
uses: peter-evans/create-pull-request@v6
78+
uses: peter-evans/create-pull-request@v7
8779
with:
8880
token: ${{ secrets.GITHUB_TOKEN }}
89-
commit-message: "Update fpm to ${{ env.LATEST_VERSION }}"
81+
commit-message: "Update fpm to ${{ env.LATEST_VERSION }} with timestamp"
9082
title: "Update fpm to ${{ env.LATEST_VERSION }}"
9183
body: |
9284
This PR automatically updates the fpm formula to version ${{ env.LATEST_VERSION }}.
9385
9486
**Changes:**
9587
- Updated URL to ${{ env.LATEST_VERSION_V }} release
9688
- Updated SHA256 to match the new release
89+
- Added timestamp to force PR: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
9790
9891
This PR was created automatically by GitHub Actions.
9992
branch: ${{ env.BRANCH_NAME }}
@@ -102,19 +95,17 @@ jobs:
10295
automated-pr
10396
version-bump
10497
105-
# Wait for test-bot CI to complete
98+
# Wait for test-bot CI to complete (unchanged)
10699
- name: Wait for test-bot to complete
107100
if: env.UPDATE_NEEDED == 'true' && steps.create-pr.outputs.pull-request-number
108101
run: |
109-
# Wait for CI to start and finish (maximum 30 minutes)
110102
echo "Waiting for test-bot workflow to complete..."
111103
PR_NUMBER=${{ steps.create-pr.outputs.pull-request-number }}
112104
timeout=1800 # 30 minutes in seconds
113105
interval=60 # Check every minute
114106
elapsed=0
115107
116108
while [ $elapsed -lt $timeout ]; do
117-
# Check if test-bot workflow has completed
118109
STATUS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
119110
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=completed&event=pull_request&head_sha=$(git rev-parse HEAD)")
120111
@@ -141,7 +132,6 @@ jobs:
141132
exit 1
142133
fi
143134
144-
# Add label to trigger pr-pull workflow
145135
- name: Add pr-pull label
146136
if: env.UPDATE_NEEDED == 'true' && steps.create-pr.outputs.pull-request-number
147137
uses: actions/github-script@v6

0 commit comments

Comments
 (0)