diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8c81a2e4cc59dc8f419c1ed3259b6a5e60f5e465..2b2467d137d1d358504829a6ceda4722ffaffb77 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,12 +6,14 @@ workflow: - if: $CI_COMMIT_REF_PROTECTED == "true" include: + - local: opentofu_versions.yaml - local: tests/unit.gitlab-ci.yml rules: - if: $SKIP_TESTS == "true" when: never - changes: - src/gitlab-tofu.sh + - opentofu_versions.yaml - Dockerfile - .gitlab-ci.yml - tests/unit.gitlab-ci.yml @@ -23,6 +25,7 @@ include: when: never - changes: - src/gitlab-tofu.sh + - opentofu_versions.yaml - Dockerfile - .gitlab-ci.yml - templates/*.yml @@ -55,19 +58,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 @@ -117,11 +115,22 @@ gitlab-opentofu-image:build: - if: $CI_COMMIT_TAG - changes: - Dockerfile + - opentofu_versions.yaml - .gitlab-ci.yml - src/**/* - 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: [] @@ -135,6 +144,7 @@ check-readme: - if: $CI_COMMIT_TAG - changes: - Makefile + - opentofu_versions.yaml - .gitlab-ci.yml - README.md - .gitlab/README.md.template 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/CONTRIBUTING.md b/CONTRIBUTING.md index 71f13467937d5c72218595c814f6737f02f3ccf7..b76bce312f8ddd90b87c84e44e287eddcae9bb8d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,16 +9,19 @@ from [`.gitlab/README.md.template`](.gitlab/README.md.template). ## Upgrade OpenTofu versions -When adding new OpenTofu versions the following places need to be updated: - -| File | What | -| ------------------------------------------------------------ | ----------------------------------------------------------------------------------------- | -| [`templates/full-pipeline.yml`](templates/full-pipeline.yml) | The `default` value and `options` list of the `sepc.inputs.opentofu_versions` entry. | -| [`.gitlab-ci.yml`](.gitlab-ci.yml) | The `.opentofu_versions.parallel.matrix` list and the `LATEST_OPENTOFU_VERSION` variable. | - -All of the above definitions have to match each other. -We currently need to change it in multiple places, because there is not a good way to share information -from the templates and the components pipeline defintion - at least in the features we'd like to use them. +The file `opentofu_versions.yaml` in the root of the project acts as +Single Source of Truth (SSoT) for the OpenTofu versions currently supported. +The versions in the templates are rendered by the +`./.gitlab/scripts/update-opentofu-versions.sh` script and the versions in +the `.gitlab-ci.yml` file are referencing the data from the SSoT file by +using a combination of CI includes and `!reference`. + +To update the supported OpenTofu versions perform the following steps: + +- Update the SSoT file with the new latest version and supported versions. +- Run the `./.gitlab/scripts/update-opentofu-versions.sh` script. +- Commit the changes. +- Submit Merge Request. ## Releasing 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' diff --git a/templates/apply.yml b/templates/apply.yml index e2d37785e6a28c5aa3c51d7e1e64c37ed004d1b1..f57d7f9d440b4958eccaacf6cc2ecc9b05b1a09d 100644 --- a/templates/apply.yml +++ b/templates/apply.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/custom-command.yml b/templates/custom-command.yml index f1f9f903bf04c8bd90400138d35312ee4c7d8534..b38a20c882741c8c088808af20598dda1b1bb994 100644 --- a/templates/custom-command.yml +++ b/templates/custom-command.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/destroy.yml b/templates/destroy.yml index cd9a743184f27352aac9d355f297f24645db7c47..748ef2829146c0997581380d628ea838db6dd159 100644 --- a/templates/destroy.yml +++ b/templates/destroy.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/fmt.yml b/templates/fmt.yml index 57fa7b214440a4186ff35da58c290ec09394251f..cb8d1308d95eebc040b34effd5fbb0d030b3d176 100644 --- a/templates/fmt.yml +++ b/templates/fmt.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/full-pipeline.yml b/templates/full-pipeline.yml index f0e4dd4afa7ae63549b65f206a31e5963a84a878..5654671803807be0a68c3142cbadce77968e3e42 100644 --- a/templates/full-pipeline.yml +++ b/templates/full-pipeline.yml @@ -27,13 +27,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/job-templates.yml b/templates/job-templates.yml index e6a0fe8ce97e4372c60d9db75ab1e235f563307b..31338dacc39255c4446a1561615be0ded551f101 100644 --- a/templates/job-templates.yml +++ b/templates/job-templates.yml @@ -27,13 +27,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/plan.yml b/templates/plan.yml index 08d0110eed6be150b7a36120788b6665ba4f4935..58255d5de71288ac1d457fff4fa3bb6312964c06 100644 --- a/templates/plan.yml +++ b/templates/plan.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images @@ -97,11 +97,6 @@ spec: image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - - | - args="" - if [ "$[[ inputs.destroy ]]" == "true" ]; then - echo "Planning for a destroy" - args="-destroy" - fi + - "args=\"\"\nif [ \"$[[ inputs.destroy ]]\" == \"true\" ]; then \n echo \"Planning for a destroy\"\n args=\"-destroy\"\nfi\n" - gitlab-tofu plan $args - gitlab-tofu plan-json diff --git a/templates/test.yml b/templates/test.yml index 29767e4b2c2b61b1a6325ccb89e1114a849a18f1..8f651074a4ffe0618a809c5a653cf39cad1cb138 100644 --- a/templates/test.yml +++ b/templates/test.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/validate-plan-apply.yml b/templates/validate-plan-apply.yml index 7608be908dd444e97e6c41eaafde10b72ffc6d16..258662b112d9850f5d27d9e1e1698c044f56ad3b 100644 --- a/templates/validate-plan-apply.yml +++ b/templates/validate-plan-apply.yml @@ -21,13 +21,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/validate-plan-destroy.yml b/templates/validate-plan-destroy.yml index 35c51a92ba7feb2f87e6738e8faaaf51095c6a6e..60f2fb6594431d7b7968b3f6a821b69ee138caec 100644 --- a/templates/validate-plan-destroy.yml +++ b/templates/validate-plan-destroy.yml @@ -21,13 +21,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/validate-plan.yml b/templates/validate-plan.yml index 145e858aaabc926bd87de2f6a020022037e856e7..480f0684e9203240301d8d749129096646bc2ee3 100644 --- a/templates/validate-plan.yml +++ b/templates/validate-plan.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images diff --git a/templates/validate.yml b/templates/validate.yml index 2b1b407e3efbe2c93072d677a0c4e67d6c9d281d..3be97a19b5f1cb90642eabe6a772bbe0f5b59a9c 100644 --- a/templates/validate.yml +++ b/templates/validate.yml @@ -18,13 +18,13 @@ spec: opentofu_version: default: '1.7.1' options: - - '$OPENTOFU_VERSION' - '1.7.1' - '1.7.0' - '1.7.0-alpha1' - '1.6.2' - '1.6.1' - '1.6.0' + - '$OPENTOFU_VERSION' description: 'OpenTofu version that should be used.' # Images