-
Notifications
You must be signed in to change notification settings - Fork 46
140 lines (121 loc) · 5.09 KB
/
automation-release.yaml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Conditionally Release the SDK
on:
pull_request:
types: ['closed']
concurrency:
group: 'release-${{ github.head_ref }}'
cancel-in-progress: true
jobs:
release-go-sdk:
if: ${{ github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'release-once-merged') }}
runs-on: custom-linux-medium
permissions:
contents: write
outputs:
latest_tag: ${{ steps.version-number.outputs.latest_tag }}
should_update_azurerm: ${{ steps.results.outputs.should_update_azurerm }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: ./.go-version
- name: run the unit tests
run: |
make tools
make test
- id: version-number
name: "Determining the Version Number.."
run: |
latestTag=$(./scripts/determine-git-tag.sh)
echo "latest_tag=$latestTag" >> "$GITHUB_OUTPUT"
shell: bash
- name: "Publish the Git Tag"
run: |
./scripts/publish-git-tag.sh ${{ steps.version-number.outputs.latest_tag }}
shell: bash
- id: results
name: "collecting outputs"
run: |
echo "should_update_azurerm=${{ github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'update-azurerm-after-release') }}" >> "$GITHUB_OUTPUT"
shell: bash
conditionally-update-azurerm:
needs: [release-go-sdk]
if: ${{github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'update-azurerm-after-release') }}
runs-on: custom-linux-xl
outputs:
has_changes_to_push: ${{ steps.update-azurerm-provider.outputs.has_changes_to_push }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: ./.go-version
- name: "Launch SSH Agent"
run: |
# launch an ssh agent and export it's env vars
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
env:
SSH_AUTH_SOCK: /tmp/azurerm_ssh_agent.sock
- name: "Load SSH Key"
run: |
# load the Deployment Write Key for the AzureRM repository
echo "${{ secrets.AZURERM_DEPLOYMENT_WRITE_KEY }}" | ssh-add -
env:
SSH_AUTH_SOCK: /tmp/azurerm_ssh_agent.sock
- id: update-azurerm-provider
name: "Update then push the AzureRM Provider"
run: |
# update the provider
./scripts/update-azurerm-provider.sh ${{ needs.release-go-sdk.outputs.latest_tag }}
# then read the result out
has_changes_to_push="$(cat ./tmp/has-changes-to-push.txt)"
echo "Has Changes to Push: ${has_changes_to_push}"
echo "has_changes_to_push=$has_changes_to_push" >> "$GITHUB_OUTPUT"
shell: bash
env:
GIT_COMMIT_USERNAME: "hc-github-team-tf-azure"
RUNNING_IN_AUTOMATION: "yep"
SSH_AUTH_SOCK: /tmp/azurerm_ssh_agent.sock
- name: "Remove the Key from the SSH Agent"
if: always()
run: |
# remove the ssh key
ssh-add -D
env:
SSH_AUTH_SOCK: /tmp/azurerm_ssh_agent.sock
- name: "Terminate the SSH Agent"
if: always()
run: |
pkill -9 ssh-agent
- name: Wait 60s for the other Github Action to open the PR
if: success()
run: |
echo "Sleeping 60s to give Github time to create the PR.."
sleep 60
- id: comment-on-the-pr
name: Comment on the PR
uses: nick-fields/retry@14672906e672a08bd6eeb15720e9ed3ce869cdd4 # v2.9.0
with:
max_attempts: 20
polling_interval_seconds: 15
retry_on: any
shell: bash
timeout_seconds: 30
command: |
echo "Determining if has changes to push.."
has_changes_to_push="${{ steps.update-azurerm-provider.outputs.has_changes_to_push }}"
echo "Has Changes to Push: ${has_changes_to_push}"
if [[ "${has_changes_to_push}" == "yes" ]]; then
echo "Finding the PR number.."
pr_number=$(gh pr list --repo="hashicorp/terraform-provider-azurerm" --search "author:hc-github-team-tf-azure sort:created-desc is:pr is:open" --json "headRefName,number" | jq '.[] | select(.headRefName=="auto-deps-pr/updating-go-azure-sdk-to-${{ needs.release-go-sdk.outputs.latest_tag }}") | .number')
if [[ "${pr_number}" == "" ]]; then
# not ready yet
echo "PR Number not found, not available yet?"
exit 1
fi
echo "PR Number was ${pr_number}"
gh issue comment $pr_number --repo "hashicorp/terraform-provider-azurerm" --body-file ./tmp/pr-description.txt
fi
env:
GH_TOKEN: "${{ secrets.AZURERM_COMMENT_KEY }}"