Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update examples link during release process #2148

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 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: 'changelogbot'

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.
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: 'changelogbot'

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
45 changes: 45 additions & 0 deletions .github/workflows/run-script-and-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Run Script and Commit Changes

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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted this as it will also contain logic for commit signing and configuring github PAT.

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Curious why we are not using "in-place" (-I flag)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went for this approach initially but the implementation of sed in macOS vs Linux handles the -i parameter differently. Opted for having same behaviour in CI vs running locally by simplifying how the command is invoked.

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