diff --git a/.github/workflows/go-version-workflow.yaml b/.github/workflows/go-version-workflow.yaml new file mode 100644 index 0000000..b3a65cc --- /dev/null +++ b/.github/workflows/go-version-workflow.yaml @@ -0,0 +1,87 @@ +# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + +# Reusable workflow to perform go version update on Golang based projects +name: Update Go Version Workflow + +on: + workflow_call: + +jobs: + go-version: + name: Update go version + runs-on: ubuntu-latest + steps: + - name: Check latest go version + run: | + GO_VERSION_STRIPPED=$(curl -sL https://go.dev/VERSION?m=text | awk 'NR==1{print $1}' | tr -cd '[:digit:].') + GO_VERSION=$(curl -sL https://go.dev/VERSION?m=text | awk 'NR==1{print $1}') + + if [[ -z "$GO_VERSION_STRIPPED" || -z "$GO_VERSION" ]]; then + echo "Error: GO_VERSION_STRIPPED or GO_VERSION is empty" + exit 1 + fi + + echo "GO_VERSION_STRIPPED=$GO_VERSION_STRIPPED" >> $GITHUB_ENV + echo "GO_VERSION=$GO_VERSION" >> $GITHUB_ENV + + - uses: actions/setup-go@v5 + with: + go-version: "${{ env.GO_VERSION_STRIPPED }}" + cache: false + check-latest: true + + - name: Checkout the code + uses: actions/checkout@v4 + + # This step will update the go version in: + # 1 - go.mod files and go.mod toolchain, if found + # 2 - csm-common.mk for UBI image + # 3 - github actions + # 4 - Dockerfiles + - name: Update go version + env: + gomod: go.mod + grep_cmd2: grep -l "go-version" + grep_cmd3: grep -l "FROM golang" + exclude_file: go-version-workflow.yaml + run: | + echo "Updating go version to ${{ env.GO_VERSION_STRIPPED }}" + + find . -name "${{ env.gomod }}" -execdir sh -c '[ -f ${{ env.gomod }} ] && go mod edit -go=${{ env.GO_VERSION_STRIPPED }} && go mod tidy' \; + + find . -name "${{ env.gomod }}" -execdir sh -c '[ -f ${{ env.gomod }} ] && grep -q "toolchain" go.mod && go mod edit -toolchain=${{ env.GO_VERSION }} && go mod tidy' \; + + if [ -f config/csm-common.mk ]; then sed -i "s/DEFAULT_GOVERSION.*/DEFAULT_GOVERSION=\"${{ env.GO_VERSION_STRIPPED }}\"/g" config/csm-common.mk; fi + + find . -type f ! -name "${{ env.exclude_file }}" -exec ${{ env.grep_cmd2 }} {} \; | while read -r file; do sed -i "s/go-version:.*/go-version: \"${{ env.GO_VERSION_STRIPPED }}\"/" "$file"; done + + find . -type f ! -name "${{ env.exclude_file }}" -exec ${{ env.grep_cmd3 }} {} \; | while read -r file; do sed -i "s/golang:.*/golang:${{ env.GO_VERSION_STRIPPED }}/" "$file"; done + + # Needed for signing commits using Github App tokens + # See: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#commit-signing + - uses: actions/create-github-app-token@v1.11.0 + id: generate-token + with: + app-id: ${{ vars.CSM_RELEASE_APP_ID }} + private-key: ${{ secrets.CSM_RELEASE_APP_PRIVATE_KEY }} + + # Must enable "allow GitHub Actions to create pull requests" setting + # Author defaults to the user who triggered the workflow run + - name: Create pull request + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ steps.generate-token.outputs.token }} + branch: "go-${{ env.GO_VERSION_STRIPPED }}" + commit-message: "Update go version to ${{ env.GO_VERSION_STRIPPED }}" + title: "Update go version to ${{ env.GO_VERSION_STRIPPED }}" + body: | + Go version updated to ${{ env.GO_VERSION_STRIPPED }} + Auto-generated by [common-github-actions](https://github.com/dell/common-github-actions) + sign-commits: true + delete-branch: true diff --git a/.github/workflows/go-version.yaml b/.github/workflows/go-version.yaml new file mode 100644 index 0000000..1ba387e --- /dev/null +++ b/.github/workflows/go-version.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + +# Reusable workflow to perform go version update on Golang based projects +name: Go Version Update + +on: + workflow_dispatch: + repository_dispatch: + types: [go-update-workflow] + +jobs: + # go version update + go-version-update: + uses: dell/common-github-actions/.github/workflows/go-version-workflow.yaml@main + name: Go Version Update + secrets: inherit diff --git a/.github/workflows/trigger-go-workflow.yaml b/.github/workflows/trigger-go-workflow.yaml new file mode 100644 index 0000000..7ba09dc --- /dev/null +++ b/.github/workflows/trigger-go-workflow.yaml @@ -0,0 +1,79 @@ +# Copyright (c) 2024 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + +# Trigger workflow for go version update on CSM projects +name: Trigger Go Version Workflow + +on: + # Can be manually triggered + workflow_dispatch: + inputs: + internal-repositories: + description: 'Internal repositories to trigger workflow against. Matrix example: "org/repo1, org/repo2"' + required: false + +# environment variables +env: + WF_ORG: dell + INTERNAL_REPOS: ${{ github.event.inputs.internal-repositories }} + +jobs: + trigger: + name: Trigger Go Version Update + runs-on: ubuntu-latest + + strategy: + matrix: + repo: + [ + "$WF_ORG/cert-csi", + "$WF_ORG/common-github-actions", + "$WF_ORG/cosi", + "$WF_ORG/csi-metadata-retriever", + "$WF_ORG/csi-powerflex", + "$WF_ORG/csi-powermax", + "$WF_ORG/csi-powerscale", + "$WF_ORG/csi-powerstore", + "$WF_ORG/csi-unity", + "$WF_ORG/csi-volumegroup-snapshotter", + "$WF_ORG/csm", + "$WF_ORG/csm-authorization", + "$WF_ORG/csm-docs", + "$WF_ORG/csm-metrics-powermax", + "$WF_ORG/csm-metrics-powerscale", + "$WF_ORG/csm-metrics-powerstore", + "$WF_ORG/csm-metrics-unity", + "$WF_ORG/csm-observability", + "$WF_ORG/csm-operator", + "$WF_ORG/csm-replication", + "$WF_ORG/dell-csi-extensions", + "$WF_ORG/gobrick", + "$WF_ORG/gocsi", + "$WF_ORG/gofsutil", + "$WF_ORG/goiscsi", + "$WF_ORG/gonvme", + "$WF_ORG/goobjectscale", + "$WF_ORG/gopowermax", + "$WF_ORG/gopowerscale", + "$WF_ORG/gopowerstore", + "$WF_ORG/goscaleio", + "$WF_ORG/gounity", + "$WF_ORG/karavi-metrics-powerflex", + "$WF_ORG/karavi-resiliency", + "$INTERNAL_REPOS", + ] + + steps: + - name: Trigger Go Version Update + uses: peter-evans/repository-dispatch@v3 + with: + # For token information, see: https://github.com/peter-evans/repository-dispatch/tree/main?tab=readme-ov-file#token + token: ${{ secrets.CSMBOT_PAT }} + repository: ${{ matrix.repo }} + event-type: go-update-workflow + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' diff --git a/README.md b/README.md index a590e33..46017ea 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ name: Release Gobrick # Invocable as a reusable workflow # Can be manually triggered on: - workflow_call: + workflow_call: workflow_dispatch: inputs: version: @@ -100,6 +100,28 @@ jobs: name: Release Go Client Libraries ``` +### go-version-workflow + +This workflow updates to the latest go version in repositories that utilize Golang as the primary development language. The workflow is triggered by https://github.com/dell/common-github-actions/actions/workflows/trigger-go-workflow.yaml or can be triggered manually. + +The workflow does not accept any parameters and can be used from any repository by creating a workflow that resembles the following +Note: Workflows that call reusable workflows in the same organization or enterprise can use the inherit keyword to implicitly pass the secrets. See: https://docs.github.com/en/actions/sharing-automations/reusing-workflows#passing-inputs-and-secrets-to-a-reusable-workflow. + +```yaml +name: Go Version Update + +on: + workflow_dispatch: + repository_dispatch: + types: [go-update-workflow] + +jobs: + go-version-update: + uses: dell/common-github-actions/.github/workflows/go-version-workflow.yaml@main + name: Go Version Update + secrets: inherit +``` + ## Support Don’t hesitate to ask! Contact the team and community on [our support](./docs/SUPPORT.md).