-
Notifications
You must be signed in to change notification settings - Fork 93
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 #489 from spyrkob/update_action
[#483] Github action to update blog post date
- Loading branch information
Showing
1 changed file
with
80 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,80 @@ | ||
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='' | ||
PR_TITLE="" | ||
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))" | ||
PR_TITLE="Update date of PR: $(gh pr view 1 --repo "${REPO_ID}" --json title --jq '.title')" | ||
else | ||
echo "Using branch main" | ||
FIX_BRANCH_NAME="fix_pr_main" | ||
SOURCE_LINK="[main]($(gh browse -b main -n --repo "${REPO_ID}"))" | ||
PR_TITLE="Update date of post: ${OLD_POST}" | ||
fi | ||
if [ ! -f "_posts/${OLD_POST}" ]; then | ||
echo "Blog post ${OLD_POST} not found" | ||
exit 1 | ||
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 "Creating a new branch: " | ||
git checkout -b "${FIX_BRANCH_NAME}" | ||
echo "Committing changes and creating update PR" | ||
git config --global user.name "${COMMIT_USERNAME}" | ||
git config --global user.email "${COMMIT_EMAIL}" | ||
git commit -am "Update ${OLD_POST} blog date" | ||
git push --set-upstream origin "${FIX_BRANCH_NAME}" | ||
gh pr create --title "${PR_TITLE}"\ | ||
--body "Date update for ${OLD_POST} from ${SOURCE_LINK}"\ | ||
--repo "${REPO_ID}" |