Skip to content

Commit

Permalink
chore: Update examples link during release process (#2148)
Browse files Browse the repository at this point in the history
* chore: Update examples link during release process

* add comment

* fix: make commits run one after another

* adjust name for commit author
  • Loading branch information
AgustinBettati authored Apr 15, 2024
1 parent 7146a46 commit eb01c2d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 19 deletions.
46 changes: 27 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]'
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 [email protected]
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: '[email protected]'
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
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/run-script-and-commit.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions scripts/update-examples-reference-in-docs.sh
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ We ship binaries but do not prioritize fixes for the following operating system

## Examples from MongoDB and the Community

<!-- NOTE: the below examples link is updated during the release process, when doing changes in the following sentence verify scripts/update-examples-reference-in-docs.sh is not impacted-->
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.

Expand Down

0 comments on commit eb01c2d

Please sign in to comment.