2024-09-08 11:16:37 +00:00
|
|
|
---
|
|
|
|
name: pull-requests-open
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
types:
|
|
|
|
- opened
|
|
|
|
- edited
|
|
|
|
- synchronize
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
commit-history-check:
|
|
|
|
name: Check commit compliance
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
with:
|
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
- name: Install commitizen
|
|
|
|
run: pip3 install commitizen
|
|
|
|
shell: bash
|
2024-09-08 12:51:51 +00:00
|
|
|
working-directory: ${{ gitea.workspace }}
|
2024-09-08 11:16:37 +00:00
|
|
|
|
|
|
|
- run: git log origin/${{ github.event.pull_request.base.ref }}..
|
|
|
|
|
|
|
|
- name: Verify commit message compliance
|
|
|
|
run: |
|
|
|
|
echo "cz check --rev-range origin/${{ gitea.event.pull_request.base.ref }}.."
|
|
|
|
cz check --rev-range origin/${{ gitea.event.pull_request.base.ref }}..
|
|
|
|
shell: bash
|
2024-09-08 12:51:51 +00:00
|
|
|
working-directory: ${{ gitea.workspace }}
|
2024-09-08 11:16:37 +00:00
|
|
|
|
2024-09-08 11:26:48 +00:00
|
|
|
pre-commit-check:
|
|
|
|
name: Check pre-commit status
|
|
|
|
runs-on: ubuntu-latest
|
2024-09-08 13:13:10 +00:00
|
|
|
needs: commit-history-check
|
2024-09-08 11:26:48 +00:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2024-09-08 12:44:01 +00:00
|
|
|
- name: Install pre-commit
|
2024-09-08 11:26:48 +00:00
|
|
|
run: pip3 install pre-commit
|
|
|
|
shell: bash
|
2024-09-08 12:51:51 +00:00
|
|
|
working-directory: ${{ gitea.workspace }}
|
2024-09-08 11:26:48 +00:00
|
|
|
|
2024-09-08 12:44:01 +00:00
|
|
|
- name: Install pre-commit dependencies
|
|
|
|
run: |
|
|
|
|
# terraform-docs
|
|
|
|
curl -sSLo /tmp/terraform-docs.tar.gz \
|
2024-09-08 12:51:51 +00:00
|
|
|
https://terraform-docs.io/dl/${TERRAFORM_DOCS_VERSION}/terraform-docs-${TERRAFORM_DOCS_VERSION}-$(uname)-amd64.tar.gz
|
2024-09-08 12:46:17 +00:00
|
|
|
tar -xzf /tmp/terraform-docs.tar.gz -C /tmp
|
2024-09-08 12:44:01 +00:00
|
|
|
chmod +x /tmp/terraform-docs
|
|
|
|
mv /tmp/terraform-docs /usr/local/bin/terraform-docs
|
2024-09-08 12:51:51 +00:00
|
|
|
rm -rf /tmp/*
|
|
|
|
|
|
|
|
# opentofu
|
|
|
|
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh \
|
|
|
|
-o install-opentofu.sh
|
|
|
|
chmod +x install-opentofu.sh
|
|
|
|
./install-opentofu.sh --install-method standalone --opentofu-version $OPENTOFU_VERSION
|
|
|
|
rm -f install-opentofu.sh
|
2024-09-08 12:44:01 +00:00
|
|
|
shell: bash
|
2024-09-08 12:51:51 +00:00
|
|
|
working-directory: ${{ gitea.workspace }}
|
|
|
|
env:
|
|
|
|
OPENTOFU_VERSION: 1.8.0
|
|
|
|
TERRAFORM_DOCS_VERSION: v0.18.0
|
2024-09-08 12:44:01 +00:00
|
|
|
|
2024-09-08 11:26:48 +00:00
|
|
|
- name: Verify pre-commit status
|
|
|
|
run: pre-commit run --all
|
|
|
|
shell: bash
|
2024-09-08 12:51:51 +00:00
|
|
|
working-directory: ${{ gitea.workspace }}
|
2024-09-09 18:51:06 +00:00
|
|
|
|
|
|
|
end-to-end-tests:
|
|
|
|
name: Run E2E tofu tests
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: pre-commit-check
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: Install required packages
|
|
|
|
run: |
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y curl jq
|
|
|
|
|
|
|
|
curl https://vault.ednz.fr/v1/ednz-root-ca/ca -o /tmp/ednz_ca
|
|
|
|
openssl x509 -inform DER -in /tmp/ednz_ca -out /usr/local/share/ca-certificates/ednz_ca.crt -outform pem
|
|
|
|
update-ca-certificates
|
|
|
|
|
|
|
|
- name: Install OpenTofu
|
|
|
|
uses: opentofu/setup-opentofu@v1
|
|
|
|
with:
|
|
|
|
tofu_version: 1.8.2
|
|
|
|
|
2024-09-10 16:55:49 +00:00
|
|
|
- name: Get secrets from vault
|
|
|
|
id: import-secrets
|
|
|
|
uses: hashicorp/vault-action@v3
|
|
|
|
with:
|
|
|
|
url: "https://vault.ednz.fr"
|
|
|
|
method: approle
|
|
|
|
roleId: ${{ secrets.VAULT_APPROLE_ID }}
|
|
|
|
secretId: ${{ secrets.VAULT_APPROLE_SECRET_ID }}
|
|
|
|
secrets: |
|
|
|
|
kv/data/cicd/vault/infrabuilder approle_id | VAULT_INFRABUILDER_APPROLE_ID ;
|
|
|
|
kv/data/cicd/vault/infrabuilder approle_secret_id | VAULT_INFRABUILDER_APPROLE_SECRET_ID ;
|
|
|
|
|
2024-09-09 18:51:06 +00:00
|
|
|
- name: Get required credentials
|
|
|
|
id: tofu-auth
|
|
|
|
run: |
|
2024-09-10 16:55:49 +00:00
|
|
|
VAULT_TOKEN=$(curl --silent --request POST --data '{"role_id": "${{ steps.import-secrets.outputs.VAULT_INFRABUILDER_APPROLE_ID }}","secret_id": "${{ steps.import-secrets.outputs.VAULT_INFRABUILDER_APPROLE_SECRET_ID }}"}' https://vault.ednz.fr/v1/auth/approle/login | jq -r .auth.client_token)
|
2024-09-09 18:51:06 +00:00
|
|
|
echo "vault_token=$VAULT_TOKEN" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
- name: Tofu init
|
|
|
|
run: tofu init
|
|
|
|
shell: bash
|
|
|
|
working-directory: ${{ gitea.workspace }}
|
|
|
|
|
|
|
|
- name: Tofu test
|
|
|
|
run: tofu test
|
|
|
|
shell: bash
|
|
|
|
working-directory: ${{ gitea.workspace }}
|
2024-09-09 18:54:43 +00:00
|
|
|
env:
|
|
|
|
VAULT_TOKEN: ${{ steps.tofu-auth.outputs.vault_token }}
|