11name : Update Noobaa-Core container image tag
22
33on :
4+ schedule :
5+ - cron : ' 0 0 1 * *'
46 workflow_dispatch :
5- inputs :
6- container_image_tag :
7- description : ' The container image tag for noobaa-core'
8- required : true
97
108permissions :
119 contents : write
@@ -17,19 +15,26 @@ jobs:
1715 runs-on : ubuntu-latest
1816 timeout-minutes : 90
1917 env :
20- GITHUB_TOKEN : ${{ secrets.GHACTION_TOKEN_WRITE }} # We need a token with write permissions to create/merge the PR
18+ GITHUB_TOKEN : ${{ secrets.GHACTION_TOKEN_PR_PERMS }}
2119
2220 steps :
2321 - name : Checkout master
2422 uses : actions/checkout@v4
2523 with :
2624 ref : master
2725
26+ - name : Generate container image tag
27+ id : generate_tag
28+ run : |
29+ tag="master-$(date -d 'yesterday' +%Y%m%d)" # using yesterday's date to ensure the image is available
30+ echo "Generated tag: $tag"
31+ echo "container_image_tag=$tag" >> "$GITHUB_OUTPUT"
32+
2833 - name : Replace ContainerImageTag
2934 uses : jacobtomlinson/gha-find-replace@v3
3035 with :
3136 find : ' ContainerImageTag = "[^"]*"'
32- replace : ' ContainerImageTag = "${{ github.event.inputs .container_image_tag }}"'
37+ replace : ' ContainerImageTag = "${{ steps.generate_tag.outputs .container_image_tag }}"'
3338 include : ' pkg/options/options.go'
3439 regex : true
3540
@@ -45,23 +50,22 @@ jobs:
4550 run : |
4651 git config --global user.email "[email protected] " 4752 git config --global user.name "NooBaa GitHub Action"
48- git checkout -b update-core-tag-${{ github.event.inputs .container_image_tag }}
53+ git checkout -B update-core-tag-${{ steps.generate_tag.outputs .container_image_tag }}
4954 git add pkg/options/options.go
50- git commit -m "chore: update noobaa-core image tag to ${{ github.event.inputs .container_image_tag }}"
51- git push origin update-core-tag-${{ github.event.inputs .container_image_tag }}
55+ git commit -m "chore: update noobaa-core image tag to ${{ steps.generate_tag.outputs .container_image_tag }}"
56+ git push origin update-core-tag-${{ steps.generate_tag.outputs .container_image_tag }}
5257
5358 - name : Create Pull Request
5459 id : create_pr
5560 run : |
5661 PR_URL=$(gh pr create \
57- --title "Update ContainerImageTag to ${{ github.event.inputs .container_image_tag }}" \
58- --body "Automated update of ContainerImageTag to ${{ github.event.inputs .container_image_tag }} in options.go" \
59- --head update-core-tag-${{ github.event.inputs .container_image_tag }} \
62+ --title "Update ContainerImageTag to ${{ steps.generate_tag.outputs .container_image_tag }}" \
63+ --body "Automated update of ContainerImageTag to ${{ steps.generate_tag.outputs .container_image_tag }} in options.go" \
64+ --head update-core-tag-${{ steps.generate_tag.outputs .container_image_tag }} \
6065 --base master)
6166 echo "PR created: $PR_URL"
6267 echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
6368
64-
6569 - name : Wait for PR checks and merge
6670 run : |
6771 echo "Waiting for checks to pass on: ${{ steps.create_pr.outputs.pr_url }}"
7377
7478 echo "Rebasing and merging PR..."
7579 gh pr merge "${{ steps.create_pr.outputs.pr_url }}" --rebase --admin --delete-branch
80+
81+ - name : Cleanup branch on failure
82+ if : always()
83+ run : |
84+ branch_name="update-core-tag-${{ steps.generate_tag.outputs.container_image_tag }}"
85+ if git ls-remote --heads origin "$branch_name" | grep -q "$branch_name"; then
86+ echo "Branch $branch_name still exists, deleting..."
87+ git push origin --delete "$branch_name"
88+ fi
0 commit comments