-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from bstansberry/Issue_549
[Issue_549] Have the update_post workflow merge main into the 'update…
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: "Update the blog post's date" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
PR_NUM: | ||
description: "PR ID to amend. Leave empty to perform changes on the main branch." | ||
required: false | ||
post_name: | ||
description: "Blog post name to amend" | ||
required: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Clone git repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: "main" | ||
- name: Update the date of ${{ github.event.inputs.post_name }} | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
set -e | ||
readonly OLD_POST="${{ github.event.inputs.post_name }}" | ||
readonly ORIGINAL_PR="${{ github.event.inputs.PR_NUM }}" | ||
readonly NEW_DATE="$(date '+%Y-%m-%d')" | ||
readonly REPO_ID="wildfly/wildfly.org" | ||
readonly COMMIT_USERNAME="Wildfly.org CI" | ||
readonly COMMIT_EMAIL="[email protected]" | ||
FIX_BRANCH_NAME='' | ||
SOURCE_LINK="" | ||
if [ "${ORIGINAL_PR}" != '' ]; then | ||
echo "Checking out PR${ORIGINAL_PR}" | ||
gh pr checkout "${ORIGINAL_PR}" --repo "${REPO_ID}" | ||
FIX_BRANCH_NAME="fix_pr_${ORIGINAL_PR}" | ||
SOURCE_LINK="[PR${ORIGINAL_PR}]($(gh browse ${ORIGINAL_PR} --repo "${REPO_ID}" -n))" | ||
else | ||
echo "Using branch main" | ||
FIX_BRANCH_NAME="fix_pr_main" | ||
SOURCE_LINK="[main]($(gh browse -b main -n --repo "${REPO_ID}"))" | ||
fi | ||
if [ ! -f "_posts/${OLD_POST}" ]; then | ||
echo "Blog post ${OLD_POST} not found" | ||
exit 1 | ||
fi | ||
echo "Creating a new branch: " | ||
git checkout -b "${FIX_BRANCH_NAME}" | ||
if [ "${ORIGINAL_PR}" != '' ]; then | ||
// Issue_549 Merge main into the PR branch to avoid permission issues if main | ||
// includes .github/workflows changes that are not in the PR branch | ||
MERGE_TARGET="$(git branch --show-current 2>/dev/null)" | ||
git merge main -m "Merge 'main' into '${MERGE_TARGET}'" | ||
fi | ||
readonly OLD_DATE=$(echo ${OLD_POST} | sed -E "s/([0-9]{4}\-[0-9]{2}\-[0-9]{2}).*/\1/") | ||
echo "Replacing ${OLD_DATE} in the blog post" | ||
sed -E -i "s/date:( *)${OLD_DATE}/date:\1${NEW_DATE}/" "_posts/${OLD_POST}" | ||
readonly NEW_POST="${NEW_DATE}"`echo "${OLD_POST}" | sed -E "s/[0-9]{4}\-[0-9]{2}\-[0-9]{2}//"` | ||
echo "Renaming the ${OLD_POST} to ${NEW_POST}" | ||
git mv _posts/${OLD_POST} _posts/${NEW_POST} | ||
echo "Committing changes and creating update PR" | ||
git config --global user.name "${COMMIT_USERNAME}" | ||
git config --global user.email "${COMMIT_EMAIL}" | ||
readonly COMMIT_MESSAGE="Update ${OLD_POST} blog date" | ||
git commit -am "${COMMIT_MESSAGE}" | ||
git push --set-upstream origin "${FIX_BRANCH_NAME}" | ||
gh pr create --title "${COMMIT_MESSAGE}"\ | ||
--body "Date update for ${OLD_POST} from ${SOURCE_LINK}"\ | ||
--repo "${REPO_ID}" |