From f5cf1d02d99b962131a0e37e7257b593f2b57acb Mon Sep 17 00:00:00 2001 From: Ben Knutson Date: Wed, 18 Feb 2026 09:52:39 +0000 Subject: [PATCH] Refactor Github Action per b/485167538 --- .github/workflows/build-downstream.yml | 6 ++++-- .github/workflows/magic-modules.yml | 14 +++++++------ .github/workflows/test-tgc.yml | 28 ++++++++++++++++++-------- .github/workflows/test-tpg.yml | 23 ++++++++++++++------- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build-downstream.yml b/.github/workflows/build-downstream.yml index f8446388ee65..c975d5424ca2 100644 --- a/.github/workflows/build-downstream.yml +++ b/.github/workflows/build-downstream.yml @@ -74,7 +74,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 @@ -106,9 +106,11 @@ 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@v2 with: name: artifact-${{ inputs.repo }} - path: output.zip \ No newline at end of file + path: output.zip diff --git a/.github/workflows/magic-modules.yml b/.github/workflows/magic-modules.yml index 1a2c88510fa2..23224c1cc74a 100644 --- a/.github/workflows/magic-modules.yml +++ b/.github/workflows/magic-modules.yml @@ -20,9 +20,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 @@ -31,7 +31,9 @@ jobs: run: pip install yamllint - 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}} rake-tests: runs-on: ubuntu-22.04 steps: @@ -46,8 +48,8 @@ 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: Set up Ruby uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 with: diff --git a/.github/workflows/test-tgc.yml b/.github/workflows/test-tgc.yml index 1546a5c856ee..2984f1cc8a82 100644 --- a/.github/workflows/test-tgc.yml +++ b/.github/workflows/test-tgc.yml @@ -71,12 +71,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: Set up Go if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }} uses: actions/setup-go@v3 @@ -85,9 +89,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.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_BRANCH} go mod tidy make build + env: + GITHUB_EVENT_INPUTS_OWNER: ${{ github.event.inputs.owner }} + GITHUB_EVENT_INPUTS_BRANCH: ${{ github.event.inputs.branch }} - name: Run Unit Tests if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }} run: | @@ -97,9 +104,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 0b5148f7d1e2..309ec794a405 100644 --- a/.github/workflows/test-tpg.yml +++ b/.github/workflows/test-tpg.yml @@ -72,12 +72,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: Set up Go if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }} uses: actions/setup-go@v3 @@ -104,9 +108,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 }}