diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index d0fc0ec2a10b462ca9295da9cabe8e0ba12f3236..849b65d35f593fc508ef7d840b22ca3c97292f0e 100644 --- a/.gitlab/README.md.template +++ b/.gitlab/README.md.template @@ -280,6 +280,54 @@ However, we cannot use the alternative `+` which would indicate build metadata as we'd like. See https://github.com/distribution/distribution/issues/1201* +### Using with Renovate + +To keep the component versions up to date you could use [Renovate](https://docs.renovatebot.com/). + +Renovate users who use the component input `opentofu_version` should include the following `extends` +so that the OpenTofu version is raised to a maximum of the version suitable for the component: + +```json +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["local>components/opentofu"], + ... +} +``` +(You may need to adjust the path to the `components/opentofu` to match your mirror.) +Fore more details refer to the [Renovate documentation](https://docs.renovatebot.com/config-presets/). + +Some more example configurations for your `renovate.json`: + +- Package Rule to update all CI-Components + ```json + { + "matchFileNames": [ + ".gitlab-ci.yaml", + ".gitlab-ci.yml", + "templates/**/*.yaml", + "templates/**/*.yml" + ], + "groupName": "Pipeline", + "semanticCommitType": "ci", + "automerge": true + }, + ``` +- Package rule to pin only `major.minor` versions: + ```json + { + "matchManagers": ["gitlabci"], + "extractVersion": "^(?<version>\\d+\\.\\d+)" + }, + ``` +- Package rule to target a specific component: + ```json + { + "matchPackageNames": ["components/opentofu"], + "matchManagers": ["gitlabci"] + }, + ``` + ## Usage on self-managed GitLab CI/CD components are not yet distributed and available on self-managed GitLab instances. diff --git a/.gitlab/scripts/update-opentofu-versions.sh b/.gitlab/scripts/update-opentofu-versions.sh index 0337135d256d7acb0c674420ae7f325cb71f1830..bfd54706701a5ddda38957fb1bdb8007e6e7bd6a 100755 --- a/.gitlab/scripts/update-opentofu-versions.sh +++ b/.gitlab/scripts/update-opentofu-versions.sh @@ -16,7 +16,26 @@ for relative_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" "$project_dir/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" "$project_dir/opentofu_versions.yaml" > "$tmp_template_file2" + 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" "$project_dir/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" "$project_dir/opentofu_versions.yaml" > "$tmp_template_file2" diff -Bw "$template_file" "$tmp_template_file2" | patch "$template_file" - done + +renovate_config="default.json" +echo "Updating Renovate config $renovate_config ... " +yq eval-all -p yaml -I4 -o json -i ' + select(fileIndex == 0 and documentIndex == 0).packageRules[0].allowedVersions + = "<=" + + select(fileIndex == 1 and documentIndex == 0).".data".latest_version + | select(fileIndex == 0) + ' "$renovate_config" "$project_dir/opentofu_versions.yaml" diff --git a/README.md b/README.md index 7db20ca05af372a8621856c57de21e3699014365..d4d5a3805cad21e2ee42b48f0d9f68e973e24be7 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,54 @@ However, we cannot use the alternative `+` which would indicate build metadata as we'd like. See https://github.com/distribution/distribution/issues/1201* +### Using with Renovate + +To keep the component versions up to date you could use [Renovate](https://docs.renovatebot.com/). + +Renovate users who use the component input `opentofu_version` should include the following `extends` +so that the OpenTofu version is raised to a maximum of the version suitable for the component: + +```json +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["local>components/opentofu"], + ... +} +``` +(You may need to adjust the path to the `components/opentofu` to match your mirror.) +Fore more details refer to the [Renovate documentation](https://docs.renovatebot.com/config-presets/). + +Some more example configurations for your `renovate.json`: + +- Package Rule to update all CI-Components + ```json + { + "matchFileNames": [ + ".gitlab-ci.yaml", + ".gitlab-ci.yml", + "templates/**/*.yaml", + "templates/**/*.yml" + ], + "groupName": "Pipeline", + "semanticCommitType": "ci", + "automerge": true + }, + ``` +- Package rule to pin only `major.minor` versions: + ```json + { + "matchManagers": ["gitlabci"], + "extractVersion": "^(?<version>\\d+\\.\\d+)" + }, + ``` +- Package rule to target a specific component: + ```json + { + "matchPackageNames": ["components/opentofu"], + "matchManagers": ["gitlabci"] + }, + ``` + ## Usage on self-managed GitLab CI/CD components are not yet distributed and available on self-managed GitLab instances. diff --git a/default.json b/default.json new file mode 100644 index 0000000000000000000000000000000000000000..343b6c2b36f0667986adbd6d6e09bafa31a14fa5 --- /dev/null +++ b/default.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "description": "Renovate configuration for OpenTofu versioning with CI/CD Components", + "packageRules": [ + { + "matchDepNames": [ + "opentofu/opentofu" + ], + "matchFileNames": [ + ".gitlab-ci.yml", + ".gitlab-ci.yaml", + "templates/**/*.yml", + "templates/**/*.yaml" + ], + "allowedVersions": "<=1.8.2" + } + ], + "customManagers": [ + { + "customType": "regex", + "fileMatch": [ + "\\.gitlab-ci\\.ya?ml", + "templates/.*\\.ya?ml" + ], + "matchStrings": [ + "opentofu_version:\\s*['\"](?<currentValue>[^'\"]+)['\"]" + ], + "datasourceTemplate": "github-releases", + "depNameTemplate": "opentofu/opentofu", + "versioningTemplate": "semver", + "extractVersionTemplate": "^v(?<version>.*)$" + } + ] +}