diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c81a2e4cc59dc8f419c1ed3259b6a5e60f5e465..f222a53aee1561ac2a5f0dbad73526b32e99196e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,6 +6,7 @@ workflow: - if: $CI_COMMIT_REF_PROTECTED == "true" include: + - local: opentofu_versions.yaml - local: tests/unit.gitlab-ci.yml rules: - if: $SKIP_TESTS == "true" @@ -55,19 +56,14 @@ stages: .opentofu-versions: parallel: matrix: - - OPENTOFU_VERSION: '1.7.1' - - OPENTOFU_VERSION: '1.7.0' - - OPENTOFU_VERSION: '1.7.0-alpha1' - - OPENTOFU_VERSION: '1.6.2' - - OPENTOFU_VERSION: '1.6.1' - - OPENTOFU_VERSION: '1.6.0' + - OPENTOFU_VERSION: !reference [.data, supported_versions] variables: # Pipeline configuration DOCKER_DIND_IMAGE: "docker:26.1.4-dind" # OpenTofu variables - LATEST_OPENTOFU_VERSION: '1.7.1' + LATEST_OPENTOFU_VERSION: !reference [.data, latest_version] # OpenTofu image build variables: PLATFORMS: linux/amd64,linux/arm64 @@ -122,6 +118,16 @@ gitlab-opentofu-image:build: - templates/**/* - tests/**/* +check-versions: + stage: test + needs: [] + image: alpine:latest + before_script: + - apk add coreutils yq patch git + script: + - ./.gitlab/scripts/update-opentofu-versions.sh + - git diff --exit-code + check-readme: stage: test needs: [] diff --git a/.gitlab/scripts/update-opentofu-versions.sh b/.gitlab/scripts/update-opentofu-versions.sh new file mode 100755 index 0000000000000000000000000000000000000000..9798b1cf4b5817b50d9b33a3a5ba1b3083e91ff4 --- /dev/null +++ b/.gitlab/scripts/update-opentofu-versions.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +echo "Updating template files ..." + +templates="templates/apply.yml templates/custom-command.yml templates/destroy.yml templates/fmt.yml templates/full-pipeline.yml templates/job-templates.yml templates/plan.yml templates/test.yml templates/validate-plan-apply.yml templates/validate-plan-destroy.yml templates/validate-plan.yml templates/validate.yml" +for template_file in $templates; do + tmp_template_file1=$(mktemp) + tmp_template_file2=$(mktemp) + echo "Updating $template_file ... " + yq eval-all 'select(fileIndex == 0 and document_index == 0).spec.inputs.opentofu_version.default = select(fileIndex == 1).".data".latest_version | select(fileIndex == 0)' "$template_file" opentofu_versions.yaml > "$tmp_template_file1" + yq eval-all 'select(fileIndex == 0 and document_index == 0).spec.inputs.opentofu_version.options = (select(fileIndex == 1).".data".hack_templates_supported_versions | explode(.) | flatten) | select(fileIndex == 0)' "$tmp_template_file1" opentofu_versions.yaml > "$tmp_template_file2" + diff -Bw "$template_file" "$tmp_template_file2" | patch "$template_file" - +done diff --git a/Makefile b/Makefile index f6fb9153ff635fd90b7ed89fcd7e9eff948d720e..64f9297da6c5bdfe8d227a9b58023fffeb945779 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ docs: echo >> README.md echo 'The following OpenTofu versions are available with this component via the `opentofu_version` input:' >> README.md echo >> README.md - yq -r '.spec.inputs.opentofu_version.options | filter((. | test("\$$.*")) == false) | .[] | "- [`" + . + "`](https://github.com/opentofu/opentofu/releases/tag/v" + . + ")"' templates/full-pipeline.yml >> README.md + yq -r '.".data".supported_versions | .[] | "- [`" + . + "`](https://github.com/opentofu/opentofu/releases/tag/v" + . + ")"' opentofu_versions.yaml >> README.md tail -n+2 readme1 >> README.md rm -f readme0 readme1 readme_inputs.md diff --git a/opentofu_versions.yaml b/opentofu_versions.yaml new file mode 100644 index 0000000000000000000000000000000000000000..36f69a4ca6d6f546a7d356e09b48126ad78fcce9 --- /dev/null +++ b/opentofu_versions.yaml @@ -0,0 +1,12 @@ +.data: + latest_version: '1.7.1' + supported_versions: &supported_versions + - '1.7.1' + - '1.7.0' + - '1.7.0-alpha1' + - '1.6.2' + - '1.6.1' + - '1.6.0' + hack_templates_supported_versions: + - *supported_versions + - '$OPENTOFU_VERSION'