diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index fe01e015..8cc02cc2 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -14,8 +14,10 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x + cache-dependency-path: | + **/go.sum + **/go.mod - name: Download Flux manifests run: make manifests - name: Run tidy diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index cf7c8934..6e8c1d51 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -23,7 +23,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Get root directories id: dirs uses: clowdhaus/terraform-composite-actions/directories@v1.9.0 @@ -48,8 +47,7 @@ jobs: - name: Setup Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x cache-dependency-path: | **/go.sum **/go.mod diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 86345323..16db5daa 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -22,8 +22,8 @@ jobs: - name: Setup Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x + cache: false - name: Import GPG key uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 id: import_gpg diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fb625f97..65db716c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -18,8 +18,10 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x + cache-dependency-path: | + **/go.sum + **/go.mod - uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0 with: terraform_version: "${{env.TERRAFORM_VERSION}}" @@ -54,8 +56,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x - uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0 with: terraform_version: ${{ matrix.terraform }} @@ -72,8 +73,7 @@ jobs: - name: Setup Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x cache-dependency-path: | **/go.sum **/go.mod @@ -155,8 +155,7 @@ jobs: - name: Setup Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x cache-dependency-path: | **/go.sum **/go.mod @@ -210,8 +209,7 @@ jobs: - name: Setup Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version-file: 'go.mod' - cache: true + go-version: 1.22.x cache-dependency-path: | **/go.sum **/go.mod diff --git a/.github/workflows/update-flux.yaml b/.github/workflows/update-flux.yaml new file mode 100644 index 00000000..207f1e05 --- /dev/null +++ b/.github/workflows/update-flux.yaml @@ -0,0 +1,98 @@ +name: update-flux + +on: + workflow_dispatch: + schedule: + - cron: "0 * * * *" + +jobs: + update-flux: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Setup Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version: 1.22.x + cache-dependency-path: | + **/go.sum + **/go.mod + - name: Setup Flux CLI + uses: fluxcd/flux2/action@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Update component versions + id: update + run: | + + latest_release=$(flux version --client | awk '{print $2}') + + # Check if the tag was fetched successfully + if [ "$latest_release" == "null" ] || [ -z "$latest_release" ]; then + printf "Failed to fetch the latest release.\n" + exit 1 + else + printf "The latest release of Flux2 is: %s.\n" "${latest_release}" + fi + + # Obtain the current version of Flux2 leveraged in this repository + # shellcheck disable=SC2046 + current_version=$(grep 'DefaultFluxVersion' internal/utils/flux.go | awk '{ print $5 }' | tr -d '"') + printf "The current version of Flux2 in this repository is: %s.\n" "$current_version" + + # If the latest release and the current version are the same, exit + if [ "${latest_release}" == "${current_version}" ]; then + printf "The current version of Flux2 in this repository is up to date. Exiting....\n" + exit 0 + fi + + # Replace the current version with the latest release + sed -i "s/${current_version}/${latest_release}/g" internal/utils/flux.go + printf "The version of Flux2 has been updated to %s.\n" "${latest_release}" + + # Run go mod tidy to update the go.mod file + go mod edit -require github.com/fluxcd/flux2/v2@"${latest_release}" + go mod tidy -compat=1.22 + + # Run the build and generate the documentation + printf "Running the build and generating the documentation...\n" + make build + make docs + + git diff + + PR_TITLE="Update Flux to ${latest_release}" + PR_BODY=$(mktemp) + echo "- github.com/fluxcd/flux2 to ${latest_release}" >> $PR_BODY + echo " https://github.com/fluxcd/flux2/releases/${latest_release}" >> $PR_BODY + + # NB: this may look strange but it is the way it should be done to + # maintain our precious newlines + # Ref: https://github.com/github/docs/issues/21529 + echo 'pr_body<> $GITHUB_OUTPUT + cat $PR_BODY >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83 # v6.0.4 + with: + token: ${{ secrets.BOT_GITHUB_TOKEN }} + commit-message: | + ${{ steps.update.outputs.pr_title }} + + ${{ steps.update.outputs.pr_body }} + committer: GitHub + author: fluxcdbot + signoff: true + title: ${{ steps.update.outputs.pr_title }} + body: | + ${{ steps.update.outputs.pr_body }} + branch: update-components + labels: | + area/build + reviewers: ${{ secrets.ASSIGNEES }} + - name: Check output + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" diff --git a/.github/workflows/update.yaml b/.github/workflows/update.yaml deleted file mode 100644 index c34ffcf2..00000000 --- a/.github/workflows/update.yaml +++ /dev/null @@ -1,67 +0,0 @@ -name: update - -on: - workflow_dispatch: - schedule: - - cron: "0 * * * *" - -jobs: - update-flux: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - name: Setup Go - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 - with: - go-version-file: 'go.mod' - cache: true - - name: Setup Flux CLI - uses: fluxcd/flux2/action@main - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Update component versions - id: update - run: | - RELEASE_VERSION=$(flux version --client | awk '{print $2}') - CURRENT_VERSION=$(go list -m all | grep github.com/fluxcd/flux2 | awk '{print $2}') - if [[ "${RELEASE_VERSION}" != "${CURRENT_VERSION}" ]]; then - go mod edit -require github.com/fluxcd/flux2/v2@${RELEASE_VERSION} - go mod tidy -compat=1.20 - fi - git diff - - PR_TITLE="Update Flux to ${RELEASE_VERSION}" - PR_BODY=$(mktemp) - echo "- github.com/fluxcd/flux2 to ${RELEASE_VERSION}" >> $PR_BODY - echo " https://github.com/fluxcd/flux2/releases/${RELEASE_VERSION}" >> $PR_BODY - - # NB: this may look strange but it is the way it should be done to - # maintain our precious newlines - # Ref: https://github.com/github/docs/issues/21529 - echo 'pr_body<> $GITHUB_OUTPUT - cat $PR_BODY >> $GITHUB_OUTPUT - echo 'EOF' >> $GITHUB_OUTPUT - echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT - - name: Create Pull Request - id: cpr - uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83 # v6.0.4 - with: - token: ${{ secrets.BOT_GITHUB_TOKEN }} - commit-message: | - ${{ steps.update.outputs.pr_title }} - - ${{ steps.update.outputs.pr_body }} - committer: GitHub - author: fluxcdbot - signoff: true - title: ${{ steps.update.outputs.pr_title }} - body: | - ${{ steps.update.outputs.pr_body }} - branch: update-components - labels: | - area/build - reviewers: ${{ secrets.ASSIGNEES }} - - name: Check output - run: | - echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"