|
| 1 | +name: update-flux |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "0 * * * *" |
| 7 | + |
| 8 | +jobs: |
| 9 | + update-flux: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Check out code |
| 13 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 14 | + - name: Setup Go |
| 15 | + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 |
| 16 | + with: |
| 17 | + go-version: 1.22.x |
| 18 | + - name: Setup Flux CLI |
| 19 | + uses: fluxcd/flux2/action@main |
| 20 | + with: |
| 21 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + - name: Update component versions |
| 23 | + id: update |
| 24 | + run: | |
| 25 | +
|
| 26 | + latest_release=$(flux version --client | awk '{print $2}') |
| 27 | +
|
| 28 | + # Check if the tag was fetched successfully |
| 29 | + if [ "$latest_release" == "null" ] || [ -z "$latest_release" ]; then |
| 30 | + printf "Failed to fetch the latest release.\n" |
| 31 | + exit 1 |
| 32 | + else |
| 33 | + printf "The latest release of Flux2 is: %s.\n" "${latest_release}" |
| 34 | + fi |
| 35 | +
|
| 36 | + # Obtain the current version of Flux2 leveraged in this repository |
| 37 | + # shellcheck disable=SC2046 |
| 38 | + current_version=$(grep 'DefaultFluxVersion' internal/utils/flux.go | awk '{ print $5 }' | tr -d '"') |
| 39 | + printf "The current version of Flux2 in this repository is: %s.\n" "$current_version" |
| 40 | +
|
| 41 | + # If the latest release and the current version are the same, exit |
| 42 | + if [ "${latest_release}" == "${current_version}" ]; then |
| 43 | + printf "The current version of Flux2 in this repository is up to date. Exiting....\n" |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + # Replace the current version with the latest release |
| 48 | + sed -i "s/${current_version}/${latest_release}/g" internal/utils/flux.go |
| 49 | + printf "The version of Flux2 has been updated to %s.\n" "${latest_release}" |
| 50 | +
|
| 51 | + # Run go mod tidy to update the go.mod file |
| 52 | + go mod edit -require github.com/fluxcd/flux2/v2@"${latest_release}" |
| 53 | + go mod tidy -compat=1.22 |
| 54 | +
|
| 55 | + # Run the build and generate the documentation |
| 56 | + printf "Running the build and generating the documentation...\n" |
| 57 | + make build |
| 58 | + make docs |
| 59 | +
|
| 60 | + git diff |
| 61 | +
|
| 62 | + PR_TITLE="Update Flux to ${latest_release}" |
| 63 | + PR_BODY=$(mktemp) |
| 64 | + echo "- github.com/fluxcd/flux2 to ${latest_release}" >> $PR_BODY |
| 65 | + echo " https://github.com/fluxcd/flux2/releases/${latest_release}" >> $PR_BODY |
| 66 | +
|
| 67 | + # NB: this may look strange but it is the way it should be done to |
| 68 | + # maintain our precious newlines |
| 69 | + # Ref: https://github.com/github/docs/issues/21529 |
| 70 | + echo 'pr_body<<EOF' >> $GITHUB_OUTPUT |
| 71 | + cat $PR_BODY >> $GITHUB_OUTPUT |
| 72 | + echo 'EOF' >> $GITHUB_OUTPUT |
| 73 | + echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT |
| 74 | + - name: Create Pull Request |
| 75 | + id: cpr |
| 76 | + uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83 # v6.0.4 |
| 77 | + with: |
| 78 | + token: ${{ secrets.BOT_GITHUB_TOKEN }} |
| 79 | + commit-message: | |
| 80 | + ${{ steps.update.outputs.pr_title }} |
| 81 | +
|
| 82 | + ${{ steps.update.outputs.pr_body }} |
| 83 | + committer: GitHub <[email protected]> |
| 84 | + author: fluxcdbot <[email protected]> |
| 85 | + signoff: true |
| 86 | + title: ${{ steps.update.outputs.pr_title }} |
| 87 | + body: | |
| 88 | + ${{ steps.update.outputs.pr_body }} |
| 89 | + branch: update-components |
| 90 | + labels: | |
| 91 | + area/build |
| 92 | + reviewers: ${{ secrets.ASSIGNEES }} |
| 93 | + - name: Check output |
| 94 | + run: | |
| 95 | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" |
0 commit comments