-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (154 loc) · 6.99 KB
/
acceptance-tests.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
on:
pull_request:
branches:
- main
types: [opened,synchronize]
paths:
- '**.go'
workflow_dispatch:
name: Terraform & OpenTofu Acceptance Tests
jobs:
acceptance-tests-matrix:
name: ${{ matrix.cli }}
runs-on: ubuntu-latest
continue-on-error: false
environment: development
strategy:
fail-fast: true
matrix:
cli: [terraform, tofu]
outputs:
tf_version: ${{ steps.get_terraform_cli_version.outputs.version }}
tofu_version: ${{ steps.get_opentofu_cli_version.outputs.version }}
artifactory_version: ${{ steps.get_artifactory_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21
- name: Install Terraform CLI
uses: hashicorp/setup-terraform@v3
if: ${{ matrix.cli == 'terraform' }}
- name: Get Terraform CLI version
id: get_terraform_cli_version
if: ${{ matrix.cli == 'terraform' }}
run: |
TF_VERSION=$(terraform -v -json | jq -r .terraform_version)
echo $TF_VERSION
echo "version=$TF_VERSION" >> "$GITHUB_OUTPUT"
- name: Install OpenTofu CLI
uses: opentofu/setup-opentofu@v1
if: ${{ matrix.cli == 'tofu' }}
with:
tofu_wrapper: false
- name: Get OpenTofu CLI version
id: get_opentofu_cli_version
if: ${{ matrix.cli == 'tofu' }}
run: |
echo "TF_ACC_TERRAFORM_PATH=$(which tofu)" >> "$GITHUB_ENV"
echo "TF_ACC_PROVIDER_NAMESPACE=hashicorp" >> "$GITHUB_ENV"
echo "TF_ACC_PROVIDER_HOST=registry.opentofu.org" >> "$GITHUB_ENV"
TOFU_VERSION=$(tofu -v -json | jq -r .terraform_version)
echo $TOFU_VERSION
echo "version=$TOFU_VERSION" >> "$GITHUB_OUTPUT"
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
install-only: true
- name: Get Artifactory version
id: get_artifactory_version
env:
JFROG_URL: ${{ secrets.JFROG_URL }}
JFROG_ACCESS_TOKEN: ${{ secrets.JFROG_ACCESS_TOKEN }}
run: |
RT_VERSION=$(curl -s -L "${JFROG_URL}/artifactory/api/system/version" -H "Authorization: Bearer ${JFROG_ACCESS_TOKEN}" | jq -r .version)
echo $RT_VERSION
echo "version=$RT_VERSION" >> "$GITHUB_OUTPUT"
- name: Execute acceptance tests
env:
JFROG_URL: ${{ secrets.JFROG_URL }}
JFROG_ACCESS_TOKEN: ${{ secrets.JFROG_ACCESS_TOKEN }}
run: make acceptance
- name: Install provider
run: |
export PROVIDER_VERSION=$(git describe --tags --abbrev=0 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')
cat sample.tf | sed -e "s/version =.*/version = \"${PROVIDER_VERSION}\"/g" > sample.tf.tmp
cp sample.tf.tmp sample.tf && rm sample.tf.tmp
TERRAFORM_CLI=${{ matrix.cli }} make install
- name: Send workflow status to Slack
uses: slackapi/slack-github-action@v1.26.0
with:
payload: |
{
"text": "${{ github.workflow }} https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }} ${{ matrix.cli }} GitHub Action result: ${{ job.status == 'success' && ':white_check_mark:' || ':x:' }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ github.workflow }} <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ github.job }}|${{ matrix.cli }} GitHub Action result>: ${{ job.status == 'success' && ':white_check_mark:' || ':x:' }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_WEBHOOK }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
update-changelog:
runs-on: ubuntu-latest
needs: acceptance-tests-matrix
if: ${{ github.event_name == 'pull_request' }} && ${{ needs.acceptance-tests-matrix.result == 'success' }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
- name: Update CHANGELOG and push commit
env:
ARTIFACTORY_VERSION: ${{ needs.acceptance-tests-matrix.outputs.artifactory_version }}
TERRAFORM_VERSION: ${{ needs.acceptance-tests-matrix.outputs.tf_version }}
OPENTOFU_VERSION: ${{ needs.acceptance-tests-matrix.outputs.tofu_version }}
run: |
echo "Adding Artifactory version to CHANGELOG.md"
sed -i -E "0,/(##\s.+\..+\..+\s\(.+\)).*/ s/(##\s.+\..+\..+\s\(.+\)).*/\1. Tested on Artifactory $ARTIFACTORY_VERSION with Terraform $TERRAFORM_VERSION and OpenTofu $OPENTOFU_VERSION/" CHANGELOG.md
head -10 CHANGELOG.md
git add CHANGELOG.md
export REGEX="Changes to be committed*"
export GIT_STATUS=$(git status)
if [[ ${GIT_STATUS} =~ ${REGEX} ]]; then
echo "Commiting changes"
git config --global user.name 'JFrog CI'
git config --global user.email 'jfrog-solutions-ci+1@jfrog.com'
git config --get user.name
git config --get user.email
git commit --author="JFrog CI <jfrog-solutions-ci+1@jfrog.com>" -m "JFrog Pipelines - Add Artifactory version to CHANGELOG.md"
git push
else
echo "There is nothing to commit: Artifactory version hadn't changed."
fi
- name: Send workflow status to Slack
uses: slackapi/slack-github-action@v1.26.0
if: success()
with:
payload: |
{
"text": "Terraform Provider Distribution. A new PR was submitted by ${{ github.event.pull_request.user.login }} - ${{ github.event.pull_request.html_url }}, branch ${{ github.event.pull_request.base.ref }}. Changes tested successfully. <@U01H1SLSPA8> or <@UNDRUL1EU> please, review and merge.",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<http://github.com/${{ github.repository }}|Terraform Provider Distribution>. A new PR was submitted by *${{ github.event.pull_request.user.login }}* - <${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}>, branch *${{ github.event.pull_request.base.ref }}*. Changes tested successfully. <@U01H1SLSPA8> or <@UNDRUL1EU> please, review and merge."
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_WEBHOOK }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK