|
| 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 | + |
| 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 | + |
| 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 |
0 commit comments