From eb01c2d32e74fd0ebc019949cd393951781c0c16 Mon Sep 17 00:00:00 2001 From: Agustin Bettati Date: Mon, 15 Apr 2024 17:12:22 +0200 Subject: [PATCH] chore: Update examples link during release process (#2148) * chore: Update examples link during release process * add comment * fix: make commits run one after another * adjust name for commit author --- .github/workflows/release.yml | 46 ++++++++++++-------- .github/workflows/run-script-and-commit.yml | 46 ++++++++++++++++++++ scripts/update-examples-reference-in-docs.sh | 24 ++++++++++ website/docs/index.html.markdown | 1 + 4 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/run-script-and-commit.yml create mode 100755 scripts/update-examples-reference-in-docs.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cfa3b7e0ca..9ef84947da 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,40 +32,48 @@ jobs: with: atlas_cloud_env: "qa" ref: ${{ inputs.use_existing_tag == 'true' && inputs.version_number || github.ref }} + + update-examples-reference-in-docs: + needs: [ validate-version-input, run-qa-acceptance-tests ] + if: >- + always() + && inputs.use_existing_tag != 'true' + && !contains(inputs.version_number, 'pre') + && needs.validate-version-input.result == 'success' + && (needs.run-qa-acceptance-tests.result == 'skipped' || needs.run-qa-acceptance-tests.result == 'success') + uses: ./.github/workflows/run-script-and-commit.yml + with: + script_call: './scripts/update-examples-reference-in-docs.sh ${{inputs.version_number}}' + file_to_commit: 'website/docs/index.html.markdown' + commit_message: 'Update examples link in index.html.markdown for ${{ github.event.inputs.version_number }} release' + user_email: 'releasebot@mongodb.com' + user_name: 'releasebot' update-changelog-header: - runs-on: ubuntu-latest - needs: [ validate-version-input, run-qa-acceptance-tests ] - # Skipped if use_existing_tag is defined, is a pre-release, or previous jobs failed. + needs: [ validate-version-input, run-qa-acceptance-tests, update-examples-reference-in-docs ] if: >- always() && inputs.use_existing_tag != 'true' && !contains(inputs.version_number, 'pre') && needs.validate-version-input.result == 'success' && (needs.run-qa-acceptance-tests.result == 'skipped' || needs.run-qa-acceptance-tests.result == 'success') - steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 - with: - fetch-depth: 0 - - run: ./scripts/update-changelog-header-for-release.sh ${{inputs.version_number}} - - run: | - if [[ $(git status --porcelain) ]]; then - MSG="Update CHANGELOG.md header for ${{inputs.version_number}} release" - git config --local user.email changelogbot@mongodb.com - git config --local user.name changelogbot - git add CHANGELOG.md - git commit -m "$MSG" - git push - fi - + uses: ./.github/workflows/run-script-and-commit.yml + with: + script_call: './scripts/update-changelog-header-for-release.sh ${{inputs.version_number}}' + file_to_commit: 'CHANGELOG.md' + commit_message: 'Update CHANGELOG.md header for ${{ github.event.inputs.version_number }} release' + user_email: 'releasebot@mongodb.com' + user_name: 'releasebot' + release: runs-on: ubuntu-latest - needs: [ validate-version-input, run-qa-acceptance-tests, update-changelog-header ] + needs: [ validate-version-input, run-qa-acceptance-tests, update-examples-reference-in-docs, update-changelog-header ] # Release is skipped if there are failures in previous steps if: >- always() && needs.validate-version-input.result == 'success' && (needs.run-qa-acceptance-tests.result == 'skipped' || needs.run-qa-acceptance-tests.result == 'success') + && (needs.update-examples-reference-in-docs.result == 'skipped' || needs.update-examples-reference-in-docs.result == 'success') && (needs.update-changelog-header.result == 'skipped' || needs.update-changelog-header.result == 'success') steps: - name: Checkout diff --git a/.github/workflows/run-script-and-commit.yml b/.github/workflows/run-script-and-commit.yml new file mode 100644 index 0000000000..304f710447 --- /dev/null +++ b/.github/workflows/run-script-and-commit.yml @@ -0,0 +1,46 @@ +name: Run Script and Commit Changes + +# Unifies logic for running a script and commit specific changes to master. Used during release process and for updating changelog on merged PRs. +on: + workflow_call: + inputs: + script_call: + required: true + type: string + file_to_commit: + required: true + type: string + commit_message: + required: true + type: string + user_email: + required: true + type: string + user_name: + required: true + type: string + +jobs: + run_script_and_commit: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + with: + fetch-depth: 0 + + - name: Run specified script + run: ${{ inputs.script_call }} + + - name: Commit changes + run: | + if [[ $(git status --porcelain) ]]; then + git pull + git config --local user.email ${{ inputs.user_email }} + git config --local user.name ${{ inputs.user_name }} + git add ${{ inputs.file_to_commit }} + git commit -m "${{ inputs.commit_message }}" + git push + else + echo "No changes to commit." + fi diff --git a/scripts/update-examples-reference-in-docs.sh b/scripts/update-examples-reference-in-docs.sh new file mode 100755 index 0000000000..2df63f2e12 --- /dev/null +++ b/scripts/update-examples-reference-in-docs.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -euo pipefail + +: "${1?"Tag of new release must be provided"}" + +FILE_PATH="./website/docs/index.html.markdown" +RELEASE_TAG=$1 + +# Define the old URL pattern and new URL +OLD_URL_PATTERN="\[example configurations\](https:\/\/github.com\/mongodb\/terraform-provider-mongodbatlas\/tree\/[a-zA-Z0-9._-]*\/examples)" +NEW_URL="\[example configurations\](https:\/\/github.com\/mongodb\/terraform-provider-mongodbatlas\/tree\/$RELEASE_TAG\/examples)" + + +TMP_FILE_NAME="docs.tmp" +rm -f $TMP_FILE_NAME + +# Use sed to update the URL and write to temporary file +sed "s|$OLD_URL_PATTERN|$NEW_URL|g" "$FILE_PATH" > "$TMP_FILE_NAME" + +# Move temporary file to original file +mv "$TMP_FILE_NAME" "$FILE_PATH" + +echo "Link updated successfully in $FILE_PATH" diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 06a8b98d54..18b7b79c1f 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -226,6 +226,7 @@ We ship binaries but do not prioritize fixes for the following operating system ## Examples from MongoDB and the Community + We have [example configurations](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/examples) in our GitHub repo that will help both beginner and more advanced users.