-
Notifications
You must be signed in to change notification settings - Fork 93
78 lines (62 loc) · 2.63 KB
/
update_post.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
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}"
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}"