Skip to content

Commit

Permalink
Update acceptance-tests.yml
Browse files Browse the repository at this point in the history
Switch to use matrix to execute both TF and Tofu
  • Loading branch information
alexhung authored Jun 7, 2024
1 parent f7a1260 commit ad2497f
Showing 1 changed file with 13 additions and 109 deletions.
122 changes: 13 additions & 109 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ on:
name: Terraform & OpenTofu Acceptance Tests

jobs:
tf-acceptance-tests:
acceptance-tests-matrix:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: true
matrix:
cli: [terraform, tofu]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,118 +31,15 @@ jobs:
./get_helm.sh
rm get_helm.sh
- name: Install Terraform CLI
if: ${{ matrix.cli == 'terraform' }}
run: |
wget -q -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
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
sudo apt-get update
sudo apt-get install -y terraform
- name: Install GoReleaser
run: |
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt-get update
sudo apt-get install -y goreleaser
- name: Create Artifactory data directories and copy data
env:
ARTIFACTORY_LICENSE: ${{ secrets.ARTIFACTORY_LICENSE }}
run: |
mkdir -p ${{ runner.temp }}/artifactory/extra_conf
mkdir -p ${{ runner.temp }}/artifactory/var/etc
echo $ARTIFACTORY_LICENSE > ${{ runner.temp }}/artifactory/extra_conf/artifactory.lic
cp ${{ github.workspace }}/scripts/system.yaml ${{ runner.temp }}/artifactory/var/etc/system.yaml
sudo chown -R 1030:1030 ${{ runner.temp }}/artifactory/var
- name: Run Artifactory container
run: |
echo "Get latest Artifactory image tag"
helm repo add artifactory https://charts.jfrog.io
helm repo update
ARTIFACTORY_VERSION=$(helm search repo | grep "artifactory " | awk '{$1=$1};1' | cut -f3 -d " ")
echo "Start up Artifactory container"
docker run -i --name artifactory -d --rm \
-v ${{ runner.temp }}/artifactory/extra_conf:/artifactory_extra_conf \
-v ${{ runner.temp }}/artifactory/var:/var/opt/jfrog/artifactory \
-p 8081:8081 -p 8082:8082 \
releases-docker.jfrog.io/jfrog/artifactory-pro:${ARTIFACTORY_VERSION}
echo "Set localhost to a container IP address, since we run docker inside of docker"
export LOCALHOST=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.Gateway}}{{end}}' artifactory)
export JFROG_URL="http://${LOCALHOST}:8082"
echo "JFROG_URL=$JFROG_URL" >> "$GITHUB_ENV"
echo "Waiting for Artifactory services to start at ${JFROG_URL}"
until $(curl -sf -o /dev/null -m 5 ${JFROG_URL}/artifactory/api/system/ping/); do
printf '.'
sleep 5
done
echo "Waiting for Artifactory UI to start"
until $(curl -sf -o /dev/null -m 5 ${JFROG_URL}/ui/login/); do
printf '.'
sleep 5
done
export COOKIES=$(curl -s -c - "${JFROG_URL}/ui/api/v1/ui/auth/login?_spring_security_remember_me=false" \
--header "accept: application/json, text/plain, */*" \
--header "content-type: application/json;charset=UTF-8" \
--header "x-requested-with: XMLHttpRequest" \
-d '{"user":"admin","password":"'"${{ secrets.ARTIFACTORY_PASSWORD }}"'","type":"login"}' | grep FALSE)
export REFRESHTOKEN=$(echo $COOKIES | grep REFRESHTOKEN | awk '{print $7}')
export ACCESSTOKEN=$(echo $COOKIES | grep ACCESSTOKEN | awk '{print $14}')
export JFROG_ACCESS_TOKEN=$(curl -s -g --request GET "${JFROG_URL}/ui/api/v1/system/security/token?services[]=all" \
--header "accept: application/json, text/plain, */*" \
--header "x-requested-with: XMLHttpRequest" \
--header "cookie: ACCESSTOKEN=${ACCESSTOKEN}; REFRESHTOKEN=${REFRESHTOKEN}")
echo "::add-mask::$JFROG_ACCESS_TOKEN"
echo "JFROG_ACCESS_TOKEN=$JFROG_ACCESS_TOKEN" >> "$GITHUB_ENV"
- name: Execute acceptance tests
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
make install
- name: Dump Artifactory logs
uses: jwalton/gh-docker-logs@v2
if: failure()
with:
tail: '10000'
- name: Clean up Docker container
run: docker stop artifactory
- name: Send workflow status to Slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "GitHub Action result: ${{ github.workflow }} ${{ github.job }} ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "GitHub Action result: ${{ github.workflow }} ${{ github.job }} ${{ job.status }}\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

opentofu-acceptance-tests:
runs-on: ubuntu-latest
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 Helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod +x get_helm.sh
./get_helm.sh
rm get_helm.sh
- name: Install OpenTofu CLI
if: ${{ matrix.cli == 'tofu' }}
run: |
echo "Installing tooling"
sudo apt-get update
Expand Down Expand Up @@ -210,6 +112,7 @@ jobs:
--header "accept: application/json, text/plain, */*" \
--header "x-requested-with: XMLHttpRequest" \
--header "cookie: ACCESSTOKEN=${ACCESSTOKEN}; REFRESHTOKEN=${REFRESHTOKEN}")
echo "::add-mask::$JFROG_ACCESS_TOKEN"
echo "JFROG_ACCESS_TOKEN=$JFROG_ACCESS_TOKEN" >> "$GITHUB_ENV"
- name: Execute acceptance tests
run: make acceptance
Expand All @@ -218,7 +121,7 @@ jobs:
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=tofu make install
TERRAFORM_CLI=${{ matrix.cli }} make install
- name: Dump Artifactory logs
uses: jwalton/gh-docker-logs@v2
if: failure()
Expand All @@ -227,17 +130,18 @@ jobs:
- name: Clean up Docker container
run: docker stop artifactory
- name: Send workflow status to Slack
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "GitHub Action result: ${{ github.workflow }} ${{ github.job }} ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
"text": "${{ github.workflow }} GitHub Action result: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.job }}> ${{ 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 Action result: ${{ github.workflow }} ${{ github.job }} ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
"text": "${{ github.workflow }} GitHub Action result: <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.job }}> ${{ job.status 'success' && ':white_check_mark:' || ':x:' }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
}
}
]
Expand Down

0 comments on commit ad2497f

Please sign in to comment.