From f6da812457ebf48038dc8ff7ccce503aed99d074 Mon Sep 17 00:00:00 2001 From: Ben Knutson Date: Wed, 18 Feb 2026 01:18:25 +0000 Subject: [PATCH] Refactor Github Action per b/485167538 --- .github/actions/build-downstream/action.yml | 5 ++-- .github/workflows/build-downstream.yml | 4 ++- .github/workflows/gofmt.yml | 4 +-- .github/workflows/mmv1-check-templates.yml | 6 ++-- .github/workflows/mmv1-lint-product-yaml.yml | 10 ++++--- .github/workflows/reassign-reviewer.yml | 5 +++- .../teamcity-services-diff-check-weekly.yml | 12 ++++---- .../teamcity-services-diff-check.yml | 12 ++++---- .github/workflows/test-tgc.yml | 28 +++++++++++++------ .github/workflows/test-tpg.yml | 23 ++++++++++----- 10 files changed, 69 insertions(+), 40 deletions(-) diff --git a/.github/actions/build-downstream/action.yml b/.github/actions/build-downstream/action.yml index 731810d372c6..94c0776c33e5 100644 --- a/.github/actions/build-downstream/action.yml +++ b/.github/actions/build-downstream/action.yml @@ -37,6 +37,7 @@ runs: env: BASE_BRANCH: ${{ github.event.pull_request.base.ref || github.ref_name }} GITHUB_TOKEN: ${{ inputs.token }} + INPUTS_REPO: ${{ inputs.repo }} run: | set -e set -x @@ -51,7 +52,7 @@ runs: git clone $GITHUB_PATH $OUTPUT_PATH --branch $BASE_BRANCH } - GH_REPO="${{ inputs.repo }}" + GH_REPO="${INPUTS_REPO}" if [ "$GH_REPO" == "docs-examples" ] && [ "$BASE_BRANCH" == "main" ]; then BASE_BRANCH="master" fi @@ -82,4 +83,4 @@ runs: exit 1 fi - (current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .) \ No newline at end of file + (current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .) diff --git a/.github/workflows/build-downstream.yml b/.github/workflows/build-downstream.yml index af1d30a3d8e6..bd237a46dcb2 100644 --- a/.github/workflows/build-downstream.yml +++ b/.github/workflows/build-downstream.yml @@ -56,7 +56,7 @@ jobs: git clone $GITHUB_PATH $OUTPUT_PATH --branch $BASE_BRANCH } - GH_REPO="${{ inputs.repo }}" + GH_REPO="${INPUTS_REPO}" if [ "$GH_REPO" == "docs-examples" ] && [ "$BASE_BRANCH" == "main" ]; then BASE_BRANCH="master" fi @@ -88,6 +88,8 @@ jobs: fi (current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .) + env: + INPUTS_REPO: ${{ inputs.repo }} - name: Upload built artifacts uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 diff --git a/.github/workflows/gofmt.yml b/.github/workflows/gofmt.yml index 210d8936cba2..8e3ba7a8819b 100644 --- a/.github/workflows/gofmt.yml +++ b/.github/workflows/gofmt.yml @@ -21,8 +21,8 @@ jobs: run: | git config user.name "modular-magician" git config user.email "magic-modules@google.com" - git fetch origin ${{ github.base_ref }} # Fetch the base branch - git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch + git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch + git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch - name: Set up Go uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 with: diff --git a/.github/workflows/mmv1-check-templates.yml b/.github/workflows/mmv1-check-templates.yml index f8b1f4c052ce..75093e6c1047 100644 --- a/.github/workflows/mmv1-check-templates.yml +++ b/.github/workflows/mmv1-check-templates.yml @@ -22,9 +22,9 @@ jobs: cd repo git config user.name "modular-magician" git config user.email "magic-modules@google.com" - git fetch origin ${{ github.base_ref }} # Fetch the base branch - git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch + git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch + git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch - name: Check for invalid version guards run: | cd repo/tools/template-check - git diff --name-only --diff-filter=d origin/${{ github.base_ref }} ../../*.tmpl | sed 's=^=../../=g' | go run main.go + git diff --name-only --diff-filter=d origin/${GITHUB_BASE_REF} ../../*.tmpl | sed 's=^=../../=g' | go run main.go diff --git a/.github/workflows/mmv1-lint-product-yaml.yml b/.github/workflows/mmv1-lint-product-yaml.yml index 41bdcfd65ace..d7c189706f0a 100644 --- a/.github/workflows/mmv1-lint-product-yaml.yml +++ b/.github/workflows/mmv1-lint-product-yaml.yml @@ -22,9 +22,9 @@ jobs: cd repo git config user.name "modular-magician" git config user.email "magic-modules@google.com" - git fetch origin ${{ github.base_ref }} # Fetch the base branch - git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch - yamlfiles=$(git diff --name-only origin/${{ github.base_ref }} -- mmv1/products) # Compare with the base branch + git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch + git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch + yamlfiles=$(git diff --name-only origin/${GITHUB_BASE_REF} -- mmv1/products) # Compare with the base branch if [ ! -z "$yamlfiles" ]; then echo "yamlfiles=repo/${yamlfiles//$'\n'/ repo/}" >> $GITHUB_OUTPUT fi @@ -33,4 +33,6 @@ jobs: run: pip install yamllint==1.32.0 pyyaml==6.0.1 pathspec==0.12.1 --no-deps - name: Lint YAML files if: ${{ !failure() && steps.pull_request.outputs.yamlfiles != '' }} - run: yamllint -c repo/.yamllint ${{steps.pull_request.outputs.yamlfiles}} + run: yamllint -c repo/.yamllint ${STEPS_PULL_REQUEST_OUTPUTS_YAMLFILES} + env: + STEPS_PULL_REQUEST_OUTPUTS_YAMLFILES: ${{steps.pull_request.outputs.yamlfiles}} diff --git a/.github/workflows/reassign-reviewer.yml b/.github/workflows/reassign-reviewer.yml index 5581c8519865..bc6bb5deb77d 100644 --- a/.github/workflows/reassign-reviewer.yml +++ b/.github/workflows/reassign-reviewer.yml @@ -42,4 +42,7 @@ jobs: go build . - name: Run command if: steps.read-comment.outputs.match != '' - run: .ci/magician/magician reassign-reviewer ${{ github.event.issue.number }} ${{ github.event.comment.user.login }} ${{ steps.read-comment.outputs.group1 }} + run: .ci/magician/magician reassign-reviewer ${{ github.event.issue.number }} ${GITHUB_EVENT_COMMENT_USER_LOGIN} ${STEPS_READ_COMMENT_OUTPUTS_GROUP1} + env: + GITHUB_EVENT_COMMENT_USER_LOGIN: ${{ github.event.comment.user.login }} + STEPS_READ_COMMENT_OUTPUTS_GROUP1: ${{ steps.read-comment.outputs.group1 }} diff --git a/.github/workflows/teamcity-services-diff-check-weekly.yml b/.github/workflows/teamcity-services-diff-check-weekly.yml index f36999c7392b..ca586b5f522e 100644 --- a/.github/workflows/teamcity-services-diff-check-weekly.yml +++ b/.github/workflows/teamcity-services-diff-check-weekly.yml @@ -28,21 +28,21 @@ jobs: # export OUTPUT_PATH=$GOPATH/src/github.com/$UPSTREAM_OWNER/$GH_REPO # OUTPUT_PATH changes after each generate (GA/beta) - name: Set GOOGLE_REPO_PATH to path where GA provider was generated - run: echo "GOOGLE_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV + run: echo "GOOGLE_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV - name: TeamCity Google Beta Provider Generate uses: ./.github/actions/build-downstream with: repo: 'terraform-provider-google-beta' token: '$GITHUB_TOKEN' - name: Set GOOGLE_BETA_REPO_PATH to path where beta provider was generated - run: echo "GOOGLE_BETA_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV + run: echo "GOOGLE_BETA_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV - name: Check that new services have been added to the TeamCity configuration code run: | # Create lists of service packages in providers. Need to cd into repos where go.mod is to do this command. - cd ${{env.GOOGLE_REPO_PATH}} - go list -f '{{.Name}}' ${{env.GOOGLE_REPO_PATH}}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt - cd ${{env.GOOGLE_BETA_REPO_PATH}} - go list -f '{{.Name}}' ${{env.GOOGLE_BETA_REPO_PATH}}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt + cd ${GOOGLE_REPO_PATH} + go list -f '{{.Name}}' ${GOOGLE_REPO_PATH}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt + cd ${GOOGLE_BETA_REPO_PATH} + go list -f '{{.Name}}' ${GOOGLE_BETA_REPO_PATH}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt # Run tool to compare service packages in the providers vs those listed in TeamCity config files cd $GITHUB_WORKSPACE diff --git a/.github/workflows/teamcity-services-diff-check.yml b/.github/workflows/teamcity-services-diff-check.yml index ea059c466c4a..5c6af2b49f1e 100644 --- a/.github/workflows/teamcity-services-diff-check.yml +++ b/.github/workflows/teamcity-services-diff-check.yml @@ -37,7 +37,7 @@ jobs: # export OUTPUT_PATH=$GOPATH/src/github.com/$UPSTREAM_OWNER/$GH_REPO # OUTPUT_PATH changes after each generate (GA/beta) - name: Set GOOGLE_REPO_PATH to path where GA provider was generated - run: echo "GOOGLE_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV + run: echo "GOOGLE_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV - name: TeamCity Google Beta Provider Generate if: steps.generate.outcome == 'success' uses: ./.github/actions/build-downstream @@ -45,7 +45,7 @@ jobs: repo: 'terraform-provider-google-beta' token: '$GITHUB_TOKEN' - name: Set GOOGLE_BETA_REPO_PATH to path where beta provider was generated - run: echo "GOOGLE_BETA_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV + run: echo "GOOGLE_BETA_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV - name: Checkout Repository if: steps.generate.outcome == 'success' uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 @@ -53,10 +53,10 @@ jobs: if: steps.generate.outcome == 'success' run: | # Create lists of service packages in providers. Need to cd into repos where go.mod is to do this command. - cd ${{env.GOOGLE_REPO_PATH}} - go list -f '{{.Name}}' ${{env.GOOGLE_REPO_PATH}}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt - cd ${{env.GOOGLE_BETA_REPO_PATH}} - go list -f '{{.Name}}' ${{env.GOOGLE_BETA_REPO_PATH}}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt + cd ${GOOGLE_REPO_PATH} + go list -f '{{.Name}}' ${GOOGLE_REPO_PATH}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt + cd ${GOOGLE_BETA_REPO_PATH} + go list -f '{{.Name}}' ${GOOGLE_BETA_REPO_PATH}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt # Run tool to compare service packages in the providers vs those listed in TeamCity config files cd $GITHUB_WORKSPACE diff --git a/.github/workflows/test-tgc.yml b/.github/workflows/test-tgc.yml index 5c87136b2a6d..b15591574dc1 100644 --- a/.github/workflows/test-tgc.yml +++ b/.github/workflows/test-tgc.yml @@ -52,12 +52,16 @@ jobs: run: | curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \ -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \ + "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${GITHUB_EVENT_INPUTS_SHA}" \ -d '{ - "context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}", - "target_url": "${{ steps.get_job.outputs.url }}", + "context": "${GITHUB_EVENT_INPUTS_REPO}${{ env.status_suffix }}", + "target_url": "${STEPS_GET_JOB_OUTPUTS_URL}", "state": "pending" }' + env: + GITHUB_EVENT_INPUTS_SHA: ${{github.event.inputs.sha}} + GITHUB_EVENT_INPUTS_REPO: ${{ github.event.inputs.repo }} + STEPS_GET_JOB_OUTPUTS_URL: ${{ steps.get_job.outputs.url }} - name: Checkout Repository uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 with: @@ -81,9 +85,12 @@ jobs: - name: Build Terraform Google Conversion if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }} run: | - go mod edit -replace github.com/hashicorp/terraform-provider-google-beta=github.com/${{ github.event.inputs.owner }}/terraform-provider-google-beta@${{ github.event.inputs.tpgb-branch }} + go mod edit -replace github.com/hashicorp/terraform-provider-google-beta=github.com/${GITHUB_EVENT_INPUTS_OWNER}/terraform-provider-google-beta@${GITHUB_EVENT_INPUTS_TPGB_BRANCH} go mod tidy make build + env: + GITHUB_EVENT_INPUTS_OWNER: ${{ github.event.inputs.owner }} + GITHUB_EVENT_INPUTS_TPGB_BRANCH: ${{ github.event.inputs.tpgb-branch }} - name: Run Unit Tests if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }} run: | @@ -93,9 +100,14 @@ jobs: run: | curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \ -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \ + "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${GITHUB_EVENT_INPUTS_SHA}" \ -d '{ - "context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}", - "target_url": "${{ steps.get_job.outputs.url }}", - "state": "${{ job.status }}" + "context": "${GITHUB_EVENT_INPUTS_REPO}${{ env.status_suffix }}", + "target_url": "${STEPS_GET_JOB_OUTPUTS_URL}", + "state": "${JOB_STATUS}" }' + env: + GITHUB_EVENT_INPUTS_SHA: ${{github.event.inputs.sha}} + GITHUB_EVENT_INPUTS_REPO: ${{ github.event.inputs.repo }} + STEPS_GET_JOB_OUTPUTS_URL: ${{ steps.get_job.outputs.url }} + JOB_STATUS: ${{ job.status }} diff --git a/.github/workflows/test-tpg.yml b/.github/workflows/test-tpg.yml index 0436a8e809b0..d0057aeb8905 100644 --- a/.github/workflows/test-tpg.yml +++ b/.github/workflows/test-tpg.yml @@ -48,12 +48,16 @@ jobs: run: | curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \ -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \ + "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${GITHUB_EVENT_INPUTS_SHA}" \ -d '{ - "context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}", - "target_url": "${{ steps.get_job.outputs.url }}", + "context": "${GITHUB_EVENT_INPUTS_REPO}${{ env.status_suffix }}", + "target_url": "${STEPS_GET_JOB_OUTPUTS_URL}", "state": "pending" }' + env: + GITHUB_EVENT_INPUTS_SHA: ${{github.event.inputs.sha}} + GITHUB_EVENT_INPUTS_REPO: ${{ github.event.inputs.repo }} + STEPS_GET_JOB_OUTPUTS_URL: ${{ steps.get_job.outputs.url }} - name: Checkout Repository uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2 with: @@ -95,9 +99,14 @@ jobs: run: | curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \ -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \ + "https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${GITHUB_EVENT_INPUTS_SHA}" \ -d '{ - "context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}", - "target_url": "${{ steps.get_job.outputs.url }}", - "state": "${{ job.status }}" + "context": "${GITHUB_EVENT_INPUTS_REPO}${{ env.status_suffix }}", + "target_url": "${STEPS_GET_JOB_OUTPUTS_URL}", + "state": "${JOB_STATUS}" }' + env: + GITHUB_EVENT_INPUTS_SHA: ${{github.event.inputs.sha}} + GITHUB_EVENT_INPUTS_REPO: ${{ github.event.inputs.repo }} + STEPS_GET_JOB_OUTPUTS_URL: ${{ steps.get_job.outputs.url }} + JOB_STATUS: ${{ job.status }}