-
Notifications
You must be signed in to change notification settings - Fork 1.6k
101 lines (96 loc) · 4.04 KB
/
test-tgc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: TGC Build and Unit Test
permissions: read-all
env:
status_suffix: "-build-and-unit-tests"
on:
workflow_dispatch:
inputs:
owner:
description: 'The owner of the fork'
required: false
default: 'modular-magician'
repo:
description: 'The Base Repository to pull from'
required: false
default: 'terraform-google-conversion'
tpgb-branch:
description: 'The branch or sha of the tpgb execute against'
required: true
tgc-branch:
description: 'The branch or sha of the tgc execute against'
required: true
pr-number:
description: 'The pull request number in magic-modules repository'
required: true
sha:
description: "The commit SHA in magic-modules repository where the status result will be posted"
required: true
concurrency:
group: test-tgc-${{ github.event.inputs.owner }}-${{ github.event.inputs.repo }}-${{ github.event.inputs.pr-number }}
cancel-in-progress: true
jobs:
build-and-unit-test:
permissions:
statuses: write
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Get Job URL
if: ${{ !cancelled() }}
id: get_job
run: |
response=$(curl --get -Ss -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}/jobs")
html_url=$(echo "$response" | jq -r --arg job_name "${{ github.job }}" '.jobs | map(select(.name == $job_name)) | .[0].html_url')
echo "url=${html_url}" >> $GITHUB_OUTPUT
- name: Post Pending Status to Pull Request
if: ${{ !cancelled() }}
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}}" \
-d '{
"context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}",
"target_url": "${{ steps.get_job.outputs.url }}",
"state": "pending"
}'
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
repository: ${{ github.event.inputs.owner }}/${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.tgc-branch }}
fetch-depth: 2
- name: Check for Code Changes
id: pull_request
run: |
gofiles=$(git diff --name-only HEAD~1 | { grep -e "\.go$" -e "go.mod$" -e "go.sum$" -e "tfplan2cai/testdata/" || test $? = 1; })
if [ -z "$gofiles" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Set up Go
if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }}
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '^1.23'
- 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 tidy
make build
- name: Run Unit Tests
if: ${{ !failure() && steps.pull_request.outputs.has_changes == 'true' }}
run: |
make test
- name: Post Result Status to Pull Request
if: ${{ !cancelled() }}
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}}" \
-d '{
"context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}",
"target_url": "${{ steps.get_job.outputs.url }}",
"state": "${{ job.status }}"
}'