Skip to content

Commit 4ed0bb1

Browse files
Refactor Github Action per b/485167538
1 parent b520453 commit 4ed0bb1

11 files changed

Lines changed: 71 additions & 43 deletions

.github/actions/build-downstream/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ runs:
5757
env:
5858
BASE_BRANCH: ${{ github.event.pull_request.base.ref || github.ref_name }}
5959
GITHUB_TOKEN: ${{ inputs.token }}
60+
INPUTS_REPO: ${{ inputs.repo }}
6061
run: |
6162
set -e
6263
set -x
@@ -71,7 +72,7 @@ runs:
7172
git clone $GITHUB_PATH $OUTPUT_PATH --branch $BASE_BRANCH
7273
}
7374
74-
GH_REPO="${{ inputs.repo }}"
75+
GH_REPO="${INPUTS_REPO}"
7576
if [ "$GH_REPO" == "docs-examples" ] && [ "$BASE_BRANCH" == "main" ]; then
7677
BASE_BRANCH="master"
7778
fi
@@ -102,4 +103,4 @@ runs:
102103
exit 1
103104
fi
104105
105-
(current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .)
106+
(current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .)

.github/workflows/build-downstream.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
git clone $GITHUB_PATH $OUTPUT_PATH --branch $BASE_BRANCH
7575
}
7676
77-
GH_REPO="${{ inputs.repo }}"
77+
GH_REPO="${INPUTS_REPO}"
7878
if [ "$GH_REPO" == "docs-examples" ] && [ "$BASE_BRANCH" == "main" ]; then
7979
BASE_BRANCH="master"
8080
fi
@@ -106,9 +106,11 @@ jobs:
106106
fi
107107
108108
(current_dir=$(pwd) && cd $OUTPUT_PATH && zip -r "$current_dir/output.zip" .)
109+
env:
110+
INPUTS_REPO: ${{ inputs.repo }}
109111

110112
- name: Upload built artifacts
111113
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
112114
with:
113115
name: artifact-${{ inputs.repo }}
114-
path: output.zip
116+
path: output.zip

.github/workflows/gofmt.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
run: |
2222
git config user.name "modular-magician"
2323
git config user.email "magic-modules@google.com"
24-
git fetch origin ${{ github.base_ref }} # Fetch the base branch
25-
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
24+
git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch
25+
git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch
2626
- name: Set up Go
2727
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
2828
with:

.github/workflows/mmv1-check-templates.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
cd repo
2323
git config user.name "modular-magician"
2424
git config user.email "magic-modules@google.com"
25-
git fetch origin ${{ github.base_ref }} # Fetch the base branch
26-
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
25+
git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch
26+
git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch
2727
- name: Check for invalid version guards
2828
run: |
2929
cd repo/tools/template-check
30-
git diff --name-only --diff-filter=d origin/${{ github.base_ref }} ../../*.tmpl | sed 's=^=../../=g' | go run main.go
30+
git diff --name-only --diff-filter=d origin/${GITHUB_BASE_REF} ../../*.tmpl | sed 's=^=../../=g' | go run main.go

.github/workflows/mmv1-lint-product-yaml.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
cd repo
2323
git config user.name "modular-magician"
2424
git config user.email "magic-modules@google.com"
25-
git fetch origin ${{ github.base_ref }} # Fetch the base branch
26-
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
27-
yamlfiles=$(git diff --name-only origin/${{ github.base_ref }} -- mmv1/products) # Compare with the base branch
25+
git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch
26+
git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch
27+
yamlfiles=$(git diff --name-only origin/${GITHUB_BASE_REF} -- mmv1/products) # Compare with the base branch
2828
if [ ! -z "$yamlfiles" ]; then
2929
echo "yamlfiles=repo/${yamlfiles//$'\n'/ repo/}" >> $GITHUB_OUTPUT
3030
fi
@@ -33,4 +33,6 @@ jobs:
3333
run: pip install yamllint==1.32.0 pyyaml==6.0.1 pathspec==0.12.1 --no-deps
3434
- name: Lint YAML files
3535
if: ${{ !failure() && steps.pull_request.outputs.yamlfiles != '' }}
36-
run: yamllint -c repo/.yamllint ${{steps.pull_request.outputs.yamlfiles}}
36+
run: yamllint -c repo/.yamllint ${STEPS_PULL_REQUEST_OUTPUTS_YAMLFILES}
37+
env:
38+
STEPS_PULL_REQUEST_OUTPUTS_YAMLFILES: ${{steps.pull_request.outputs.yamlfiles}}

.github/workflows/mmv1-rake-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
cd repo
2323
git config user.name "modular-magician"
2424
git config user.email "magic-modules@google.com"
25-
git fetch origin ${{ github.base_ref }} # Fetch the base branch
26-
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
25+
git fetch origin ${GITHUB_BASE_REF} # Fetch the base branch
26+
git merge --no-ff origin/${GITHUB_BASE_REF} # Merge with the base branch
2727
- name: Set up Ruby
2828
uses: ruby/setup-ruby@036ef458ddccddb148a2b9fb67e95a22fdbf728b # v1.160.0
2929
with:

.github/workflows/reassign-reviewer.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ jobs:
4242
go build .
4343
- name: Run command
4444
if: steps.read-comment.outputs.match != ''
45-
run: .ci/magician/magician reassign-reviewer ${{ github.event.issue.number }} ${{ steps.read-comment.outputs.match.group1 }}
45+
run: .ci/magician/magician reassign-reviewer ${{ github.event.issue.number }} ${STEPS_READ_COMMENT_OUTPUTS_MATCH_GROUP1}
46+
env:
47+
STEPS_READ_COMMENT_OUTPUTS_MATCH_GROUP1: ${{ steps.read-comment.outputs.match.group1 }}

.github/workflows/teamcity-services-diff-check-weekly.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ jobs:
2828
# export OUTPUT_PATH=$GOPATH/src/github.com/$UPSTREAM_OWNER/$GH_REPO
2929
# OUTPUT_PATH changes after each generate (GA/beta)
3030
- name: Set GOOGLE_REPO_PATH to path where GA provider was generated
31-
run: echo "GOOGLE_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV
31+
run: echo "GOOGLE_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV
3232
- name: TeamCity Google Beta Provider Generate
3333
uses: ./.github/actions/build-downstream
3434
with:
3535
repo: 'terraform-provider-google-beta'
3636
token: '$GITHUB_TOKEN'
3737
- name: Set GOOGLE_BETA_REPO_PATH to path where beta provider was generated
38-
run: echo "GOOGLE_BETA_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV
38+
run: echo "GOOGLE_BETA_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV
3939
- name: Check that new services have been added to the TeamCity configuration code
4040
run: |
4141
# Create lists of service packages in providers. Need to cd into repos where go.mod is to do this command.
42-
cd ${{env.GOOGLE_REPO_PATH}}
43-
go list -f '{{.Name}}' ${{env.GOOGLE_REPO_PATH}}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt
44-
cd ${{env.GOOGLE_BETA_REPO_PATH}}
45-
go list -f '{{.Name}}' ${{env.GOOGLE_BETA_REPO_PATH}}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt
42+
cd ${GOOGLE_REPO_PATH}
43+
go list -f '{{.Name}}' ${GOOGLE_REPO_PATH}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt
44+
cd ${GOOGLE_BETA_REPO_PATH}
45+
go list -f '{{.Name}}' ${GOOGLE_BETA_REPO_PATH}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt
4646
4747
# Run tool to compare service packages in the providers vs those listed in TeamCity config files
4848
cd $GITHUB_WORKSPACE

.github/workflows/teamcity-services-diff-check.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ jobs:
3737
# export OUTPUT_PATH=$GOPATH/src/github.com/$UPSTREAM_OWNER/$GH_REPO
3838
# OUTPUT_PATH changes after each generate (GA/beta)
3939
- name: Set GOOGLE_REPO_PATH to path where GA provider was generated
40-
run: echo "GOOGLE_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV
40+
run: echo "GOOGLE_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV
4141
- name: TeamCity Google Beta Provider Generate
4242
if: steps.generate.outcome == 'success'
4343
uses: ./.github/actions/build-downstream
4444
with:
4545
repo: 'terraform-provider-google-beta'
4646
token: '$GITHUB_TOKEN'
4747
- name: Set GOOGLE_BETA_REPO_PATH to path where beta provider was generated
48-
run: echo "GOOGLE_BETA_REPO_PATH=${{ env.OUTPUT_PATH}}" >> $GITHUB_ENV
48+
run: echo "GOOGLE_BETA_REPO_PATH=${OUTPUT_PATH}" >> $GITHUB_ENV
4949
- name: Checkout Repository
5050
if: steps.generate.outcome == 'success'
5151
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
5252
- name: Check that new services have been added to the TeamCity configuration code
5353
if: steps.generate.outcome == 'success'
5454
run: |
5555
# Create lists of service packages in providers. Need to cd into repos where go.mod is to do this command.
56-
cd ${{env.GOOGLE_REPO_PATH}}
57-
go list -f '{{.Name}}' ${{env.GOOGLE_REPO_PATH}}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt
58-
cd ${{env.GOOGLE_BETA_REPO_PATH}}
59-
go list -f '{{.Name}}' ${{env.GOOGLE_BETA_REPO_PATH}}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt
56+
cd ${GOOGLE_REPO_PATH}
57+
go list -f '{{.Name}}' ${GOOGLE_REPO_PATH}/google/services/... > $GITHUB_WORKSPACE/provider_services_ga.txt
58+
cd ${GOOGLE_BETA_REPO_PATH}
59+
go list -f '{{.Name}}' ${GOOGLE_BETA_REPO_PATH}/google-beta/services/... > $GITHUB_WORKSPACE/provider_services_beta.txt
6060
6161
# Run tool to compare service packages in the providers vs those listed in TeamCity config files
6262
cd $GITHUB_WORKSPACE

.github/workflows/test-tgc.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ jobs:
5252
run: |
5353
curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
5454
-H "Accept: application/vnd.github.v3+json" \
55-
"https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \
55+
"https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${GITHUB_EVENT_INPUTS_SHA}" \
5656
-d '{
57-
"context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}",
58-
"target_url": "${{ steps.get_job.outputs.url }}",
57+
"context": "${GITHUB_EVENT_INPUTS_REPO}${{ env.status_suffix }}",
58+
"target_url": "${STEPS_GET_JOB_OUTPUTS_URL}",
5959
"state": "pending"
6060
}'
61+
env:
62+
GITHUB_EVENT_INPUTS_SHA: ${{github.event.inputs.sha}}
63+
GITHUB_EVENT_INPUTS_REPO: ${{ github.event.inputs.repo }}
64+
STEPS_GET_JOB_OUTPUTS_URL: ${{ steps.get_job.outputs.url }}
6165
- name: Checkout Repository
6266
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
6367
with:
@@ -81,9 +85,12 @@ jobs:
8185
- name: Build Terraform Google Conversion
8286
if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }}
8387
run: |
84-
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 }}
88+
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}
8589
go mod tidy
8690
make build
91+
env:
92+
GITHUB_EVENT_INPUTS_OWNER: ${{ github.event.inputs.owner }}
93+
GITHUB_EVENT_INPUTS_TPGB_BRANCH: ${{ github.event.inputs.tpgb-branch }}
8794
- name: Run Unit Tests
8895
if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }}
8996
run: |
@@ -93,9 +100,14 @@ jobs:
93100
run: |
94101
curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
95102
-H "Accept: application/vnd.github.v3+json" \
96-
"https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \
103+
"https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${GITHUB_EVENT_INPUTS_SHA}" \
97104
-d '{
98-
"context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}",
99-
"target_url": "${{ steps.get_job.outputs.url }}",
100-
"state": "${{ job.status }}"
105+
"context": "${GITHUB_EVENT_INPUTS_REPO}${{ env.status_suffix }}",
106+
"target_url": "${STEPS_GET_JOB_OUTPUTS_URL}",
107+
"state": "${JOB_STATUS}"
101108
}'
109+
env:
110+
GITHUB_EVENT_INPUTS_SHA: ${{github.event.inputs.sha}}
111+
GITHUB_EVENT_INPUTS_REPO: ${{ github.event.inputs.repo }}
112+
STEPS_GET_JOB_OUTPUTS_URL: ${{ steps.get_job.outputs.url }}
113+
JOB_STATUS: ${{ job.status }}

0 commit comments

Comments
 (0)