From 307a398e7a56f0fef60cb8190de5f692434dc2e5 Mon Sep 17 00:00:00 2001 From: Ben Knutson Date: Tue, 17 Feb 2026 23:53:57 +0000 Subject: [PATCH] Refactor Github Action per b/485167538 --- .github/workflows/magic-modules.yml | 14 ++++++++------ .github/workflows/test-tgc.yml | 28 ++++++++++++++++++++-------- .github/workflows/test-tpg.yml | 23 ++++++++++++++++------- 3 files changed, 44 insertions(+), 21 deletions(-) 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 7d33f3cbc60c..a50292de1032 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@v4 @@ -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 3b0c3f2fa822..b8415c0c141d 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@v4 @@ -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 }}