Skip to content

Commit eae9364

Browse files
author
Alex Hung
authored
Merge pull request #136 from jfrog/add-github-workflow-for-acceptance-tests
Add GitHub Workflow for acceptance testings
2 parents 6d137c6 + 4285e1b commit eae9364

File tree

7 files changed

+264
-12
lines changed

7 files changed

+264
-12
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
types: [opened,synchronize]
6+
paths:
7+
- '**.go'
8+
workflow_dispatch:
9+
10+
name: Terraform & OpenTofu Acceptance Tests
11+
12+
jobs:
13+
acceptance-tests-matrix:
14+
name: ${{ matrix.cli }}
15+
runs-on: ubuntu-latest
16+
continue-on-error: true
17+
environment: development
18+
strategy:
19+
fail-fast: true
20+
matrix:
21+
cli: [terraform, tofu]
22+
outputs:
23+
tf_version: ${{ steps.debug_tf_version.outputs.version }}
24+
tofu_version: ${{ steps.install_opentofu_cli.outputs.version }}
25+
artifactory_version: ${{ steps.run_artifactory_container.outputs.version }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Unshallow
30+
run: git fetch --prune --unshallow
31+
- name: Set up Go
32+
uses: actions/setup-go@v5
33+
with:
34+
go-version: 1.21
35+
- name: Install Helm
36+
run: |
37+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
38+
chmod +x get_helm.sh
39+
./get_helm.sh
40+
rm get_helm.sh
41+
- name: Install Terraform CLI
42+
id: install_terraform_cli
43+
if: ${{ matrix.cli == 'terraform' }}
44+
run: |
45+
wget -q -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
46+
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
47+
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
48+
sudo apt-get update
49+
sudo apt-get install -y terraform
50+
- name: Debug TF version
51+
id: debug_tf_version
52+
run: |
53+
TF_VERSION=$(terraform -v -json | jq -r .terraform_version)
54+
echo $TF_VERSION
55+
echo "version=$TF_VERSION" >> "$GITHUB_OUTPUT"
56+
- name: Install OpenTofu CLI
57+
id: install_opentofu_cli
58+
if: ${{ matrix.cli == 'tofu' }}
59+
run: |
60+
sudo apt-get update
61+
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
62+
echo "Set up the OpenTofu repository"
63+
sudo install -m 0755 -d /etc/apt/keyrings
64+
curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo tee /etc/apt/keyrings/opentofu.gpg >/dev/null
65+
curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | sudo gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg >/dev/null
66+
sudo chmod a+r /etc/apt/keyrings/opentofu.gpg /etc/apt/keyrings/opentofu-repo.gpg
67+
echo "Create the OpenTofu source list"
68+
echo \
69+
"deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
70+
deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | \
71+
sudo tee /etc/apt/sources.list.d/opentofu.list > /dev/null
72+
sudo chmod a+r /etc/apt/sources.list.d/opentofu.list
73+
echo "Installing OpenTofu"
74+
sudo apt-get update
75+
sudo apt-get install -y tofu
76+
echo "TF_ACC_TERRAFORM_PATH=$(which tofu)" >> "$GITHUB_ENV"
77+
echo "TF_ACC_PROVIDER_NAMESPACE=hashicorp" >> "$GITHUB_ENV"
78+
echo "TF_ACC_PROVIDER_HOST=registry.opentofu.org" >> "$GITHUB_ENV"
79+
TOFU_VERSION=$(tofu -v -json | jq -r .terraform_version)
80+
echo $TOFU_VERSION
81+
echo "version=$TOFU_VERSION" >> "$GITHUB_OUTPUT"
82+
- name: Install GoReleaser
83+
run: |
84+
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
85+
sudo apt-get update
86+
sudo apt-get install -y goreleaser
87+
- name: Create Artifactory data directories and copy data
88+
env:
89+
ARTIFACTORY_LICENSE: ${{ secrets.ARTIFACTORY_LICENSE }}
90+
run: |
91+
mkdir -p ${{ runner.temp }}/artifactory/extra_conf
92+
mkdir -p ${{ runner.temp }}/artifactory/var/etc
93+
echo $ARTIFACTORY_LICENSE > ${{ runner.temp }}/artifactory/extra_conf/artifactory.lic
94+
cp ${{ github.workspace }}/scripts/system.yaml ${{ runner.temp }}/artifactory/var/etc/system.yaml
95+
sudo chown -R 1030:1030 ${{ runner.temp }}/artifactory/var
96+
- name: Run Artifactory container
97+
id: run_artifactory_container
98+
run: |
99+
echo "Get latest Artifactory image tag"
100+
helm repo add artifactory https://charts.jfrog.io
101+
helm repo update
102+
ARTIFACTORY_VERSION=$(helm search repo | grep "artifactory " | awk '{$1=$1};1' | cut -f3 -d " ")
103+
echo "version=$ARTIFACTORY_VERSION" >> "$GITHUB_OUTPUT"
104+
echo "Start up Artifactory container"
105+
docker run -i --name artifactory -d --rm \
106+
-v ${{ runner.temp }}/artifactory/extra_conf:/artifactory_extra_conf \
107+
-v ${{ runner.temp }}/artifactory/var:/var/opt/jfrog/artifactory \
108+
-p 8081:8081 -p 8082:8082 \
109+
releases-docker.jfrog.io/jfrog/artifactory-pro:${ARTIFACTORY_VERSION}
110+
echo "Set localhost to a container IP address, since we run docker inside of docker"
111+
export LOCALHOST=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.Gateway}}{{end}}' artifactory)
112+
export JFROG_URL="http://${LOCALHOST}:8082"
113+
echo "JFROG_URL=$JFROG_URL" >> "$GITHUB_ENV"
114+
echo "Waiting for Artifactory services to start at ${JFROG_URL}"
115+
until $(curl -sf -o /dev/null -m 5 ${JFROG_URL}/artifactory/api/system/ping/); do
116+
printf '.'
117+
sleep 5
118+
done
119+
echo "Waiting for Artifactory UI to start"
120+
until $(curl -sf -o /dev/null -m 5 ${JFROG_URL}/ui/login/); do
121+
printf '.'
122+
sleep 5
123+
done
124+
export COOKIES=$(curl -s -c - "${JFROG_URL}/ui/api/v1/ui/auth/login?_spring_security_remember_me=false" \
125+
--header "accept: application/json, text/plain, */*" \
126+
--header "content-type: application/json;charset=UTF-8" \
127+
--header "x-requested-with: XMLHttpRequest" \
128+
-d '{"user":"admin","password":"'"${{ secrets.ARTIFACTORY_PASSWORD }}"'","type":"login"}' | grep FALSE)
129+
export REFRESHTOKEN=$(echo $COOKIES | grep REFRESHTOKEN | awk '{print $7}')
130+
export ACCESSTOKEN=$(echo $COOKIES | grep ACCESSTOKEN | awk '{print $14}')
131+
export JFROG_ACCESS_TOKEN=$(curl -s -g --request GET "${JFROG_URL}/ui/api/v1/system/security/token?services[]=all" \
132+
--header "accept: application/json, text/plain, */*" \
133+
--header "x-requested-with: XMLHttpRequest" \
134+
--header "cookie: ACCESSTOKEN=${ACCESSTOKEN}; REFRESHTOKEN=${REFRESHTOKEN}")
135+
echo "::add-mask::$JFROG_ACCESS_TOKEN"
136+
echo "JFROG_ACCESS_TOKEN=$JFROG_ACCESS_TOKEN" >> "$GITHUB_ENV"
137+
- name: Execute acceptance tests
138+
run: make acceptance
139+
- name: Install provider
140+
run: |
141+
export PROVIDER_VERSION=$(git describe --tags --abbrev=0 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')
142+
cat sample.tf | sed -e "s/version =.*/version = \"${PROVIDER_VERSION}\"/g" > sample.tf.tmp
143+
cp sample.tf.tmp sample.tf && rm sample.tf.tmp
144+
TERRAFORM_CLI=${{ matrix.cli }} make install
145+
- name: Dump Artifactory logs
146+
uses: jwalton/gh-docker-logs@v2
147+
if: failure()
148+
with:
149+
tail: '10000'
150+
- name: Clean up Docker container
151+
run: docker stop artifactory
152+
- name: Send workflow status to Slack
153+
uses: slackapi/[email protected]
154+
with:
155+
payload: |
156+
{
157+
"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 }}",
158+
"blocks": [
159+
{
160+
"type": "section",
161+
"text": {
162+
"type": "mrkdwn",
163+
"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 }}"
164+
}
165+
}
166+
]
167+
}
168+
env:
169+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_WEBHOOK }}
170+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
171+
172+
update-changelog:
173+
runs-on: ubuntu-latest
174+
needs: acceptance-tests-matrix
175+
if: ${{ github.event_name == 'pull_request' }}
176+
permissions:
177+
contents: write
178+
steps:
179+
- uses: actions/checkout@v4
180+
with:
181+
fetch-depth: 0
182+
ref: ${{ github.event.pull_request.head.ref }}
183+
- name: Update CHANGELOG and push commit
184+
env:
185+
ARTIFACTORY_VERSION: ${{ needs.acceptance-tests-matrix.outputs.artifactory_version }}
186+
TERRAFORM_VERSION: ${{ needs.acceptance-tests-matrix.outputs.tf_version }}
187+
OPENTOFU_VERSION: ${{ needs.acceptance-tests-matrix.outputs.tofu_version }}
188+
run: |
189+
echo "Adding Artifactory version to CHANGELOG.md"
190+
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
191+
head -10 CHANGELOG.md
192+
git add CHANGELOG.md
193+
export REGEX="Changes to be committed*"
194+
export GIT_STATUS=$(git status)
195+
if [[ ${GIT_STATUS} =~ ${REGEX} ]]; then
196+
echo "Commiting changes"
197+
git config --global user.name 'JFrog CI'
198+
git config --global user.email '[email protected]'
199+
git config --get user.name
200+
git config --get user.email
201+
git commit --author="JFrog CI <[email protected]>" -m "JFrog Pipelines - Add Artifactory version to CHANGELOG.md"
202+
git push
203+
else
204+
echo "There is nothing to commit: Artifactory version hadn't changed."
205+
fi
206+
- name: Send workflow status to Slack
207+
uses: slackapi/[email protected]
208+
if: success()
209+
with:
210+
payload: |
211+
{
212+
"text": "Terraform Provider Project. 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.",
213+
"blocks": [
214+
{
215+
"type": "section",
216+
"text": {
217+
"type": "mrkdwn",
218+
"text": "<http://github.com/${{ github.repository }}|Terraform Provider Project>. 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."
219+
}
220+
}
221+
]
222+
}
223+
env:
224+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_PR_WEBHOOK }}
225+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ dist/
33
vendor/
44
bin/
55
.idea/
6-
.github/
76
.modules/
87
.terraform*
98
terraform.d/

.goreleaser.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ signs:
4848
- "--detach-sign"
4949
- "${artifact}"
5050
release:
51+
extra_files:
52+
- glob: 'terraform-registry-manifest.json'
53+
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
5154
# If you want to manually examine the release before its live, uncomment this line:
5255
# draft: true
5356
changelog:

GNUmakefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@ PKG_NAME=pkg/${PRODUCT}
1212
PKG_VERSION_PATH=github.com/jfrog/terraform-provider-${PRODUCT}/${PKG_NAME}
1313
VERSION := $(shell git tag --sort=-creatordate | head -1 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')
1414
NEXT_VERSION := $(shell echo ${VERSION}| awk -F '.' '{print $$1 "." $$2 "." $$3 +1 }' )
15-
BUILD_PATH=terraform.d/plugins/registry.terraform.io/jfrog/${PRODUCT}/${NEXT_VERSION}/${TARGET_ARCH}
15+
16+
TERRAFORM_CLI?=terraform
17+
18+
REGISTRY_HOST=registry.terraform.io
19+
20+
ifeq ($(TERRAFORM_CLI), tofu)
21+
REGISTRY_HOST=registry.opentofu.org
22+
endif
23+
24+
BUILD_PATH=terraform.d/plugins/${REGISTRY_HOST}/jfrog/${PRODUCT}/${NEXT_VERSION}/${TARGET_ARCH}
25+
1626
SONAR_SCANNER_VERSION?=4.7.0.2747
1727
SONAR_SCANNER_HOME?=${HOME}/.sonar/sonar-scanner-${SONAR_SCANNER_VERSION}-macosx
1828

1929
default: build
2030

2131
install: clean build
22-
rm -fR .terraform.d && \
2332
mkdir -p ${BUILD_PATH} && \
2433
mv -v dist/terraform-provider-${PRODUCT}_${GORELEASER_ARCH}/terraform-provider-${PRODUCT}_v${NEXT_VERSION}* ${BUILD_PATH} && \
2534
rm -f .terraform.lock.hcl && \
2635
sed -i.bak '0,/version = ".*"/s//version = "${NEXT_VERSION}"/' sample.tf && rm sample.tf.bak && \
27-
terraform init
36+
${TERRAFORM_CLI} init
2837

2938
install_tfc: clean build_tfc
3039
mkdir -p tfc-testing/${BUILD_PATH} && \
@@ -33,8 +42,8 @@ install_tfc: clean build_tfc
3342
mv -v dist/terraform-provider-${PRODUCT}_linux_amd64_v1/terraform-provider-${PRODUCT}_v${NEXT_VERSION}* tfc-testing/terraform.d/plugins/registry.terraform.io/jfrog/${PRODUCT}/${NEXT_VERSION}/linux_amd64 && \
3443
sed -i.bak '0,/version = ".*"/s//version = "${NEXT_VERSION}"/' tfc-testing/sample.tf && rm tfc-testing/sample.tf.bak && \
3544
cd tfc-testing && \
36-
terraform providers lock -platform=linux_amd64 -platform=darwin_amd64 -fs-mirror=terraform.d/plugins && \
37-
terraform init
45+
${TERRAFORM_CLI} providers lock -platform=linux_amd64 -platform=darwin_amd64 -fs-mirror=terraform.d/plugins && \
46+
${TERRAFORM_CLI} init
3847

3948
clean:
4049
rm -fR dist terraform.d/ .terraform terraform.tfstate* .terraform.lock.hcl
@@ -63,7 +72,7 @@ test:
6372

6473
test_tfc: install_tfc
6574
cd tfc-testing && \
66-
terraform plan
75+
${TERRAFORM_CLI} plan
6776

6877
attach:
6978
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient attach $$(pgrep terraform-provider-${PRODUCT})
@@ -82,7 +91,7 @@ scan:
8291

8392
fmt:
8493
@echo "==> Fixing source code with gofmt..."
85-
@go fmt ./...
94+
@go fmt ./pkg/...
8695

8796
doc:
8897
rm -rfv docs/*

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Terraform & OpenTofu Acceptance Tests](https://github.com/jfrog/terraform-provider-project/actions/workflows/acceptance-tests.yml/badge.svg)](https://github.com/jfrog/terraform-provider-project/actions/workflows/acceptance-tests.yml)
2+
13
# Terraform Provider for Artifactory Project
24

35
[![Actions Status](https://github.com/jfrog/terraform-provider-project/workflows/release/badge.svg)](https://github.com/jfrog/terraform-provider-project/actions)

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module github.com/jfrog/terraform-provider-project
33
// if you need to do local dev, literally just uncomment the line below
44
// replace github.com/jfrog/terraform-provider-shared => ../terraform-provider-shared
55

6+
go 1.21.5
7+
68
require (
79
github.com/go-resty/resty/v2 v2.13.1
810
github.com/hashicorp/terraform-plugin-docs v0.19.4
@@ -90,7 +92,3 @@ require (
9092
gopkg.in/yaml.v2 v2.3.0 // indirect
9193
gopkg.in/yaml.v3 v3.0.1 // indirect
9294
)
93-
94-
go 1.21
95-
96-
toolchain go1.21.5

scripts/system.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## @formatter:off
2+
## JFROG ARTIFACTORY SYSTEM CONFIGURATION FILE
3+
## HOW TO USE: comment-out any field and keep the correct yaml indentation by deleting only the leading '#' character.
4+
configVersion: 1
5+
## NOTE: JFROG_HOME is a place holder for the JFrog root directory containing the deployed product, the home directory for all JFrog products.
6+
## Replace JFROG_HOME with the real path! For example, in RPM install, JFROG_HOME=/opt/jfrog
7+
8+
## NOTE: Sensitive information such as passwords and join key are encrypted on first read.
9+
## NOTE: The provided commented key and value is the default.
10+
11+
## SHARED CONFIGURATIONS
12+
## A shared section for keys across all services in this config
13+
shared:
14+
database:
15+
## To run Artifactory with any database other than PostgreSQL allowNonPostgresql set to true.
16+
allowNonPostgresql: true

0 commit comments

Comments
 (0)