-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (88 loc) · 3.09 KB
/
metadata-advanced.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Seasonal metadata post
# Grant the action permission to write to the repository
permissions:
contents: write
on:
workflow_dispatch:
schedule:
- cron: "00 02 20 Mar,Jun,Sep,Dec *"
jobs:
metadata-post:
runs-on: ubuntu-latest
name: Write metadata post
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set post title and dates
id: set-season
run: |
# Get the current month and year
MONTH=$(date +%m)
YEAR=$(date +%Y)
# Define the seasons and corresponding emojis
declare -A SEASONS=(
["03"]="Winter"
["06"]="Spring"
["09"]="Summer"
["12"]="Fall"
)
declare -A SEASON_EMOJI=(
["Winter"]="❄️"
["Spring"]="🌷"
["Summer"]="☀️"
["Fall"]="🍂"
)
# Function to set environment variables based on the season
set_environment_variables_for_season() {
local season=$1
local start_date=$2
local end_date=$3
local post_title=""
if [ "$season" = "Winter" ]; then
post_title="$(($YEAR - 1))/${YEAR} ${season}"
else
post_title="${YEAR} ${season}"
fi
echo "POST_TITLE=${post_title}" >> $GITHUB_OUTPUT
echo "START_DATE=${start_date}" >> $GITHUB_OUTPUT
echo "END_DATE=${end_date}" >> $GITHUB_OUTPUT
echo "SEASON_EMOJI=${SEASON_EMOJI[$season]}" >> $GITHUB_OUTPUT
}
# Set environment variables based on the current month
case $MONTH in
"03")
set_environment_variables_for_season ${SEASONS[$MONTH]} "$(($YEAR - 1))-12-21" "${YEAR}-03-20"
;;
"06")
set_environment_variables_for_season ${SEASONS[$MONTH]} "${YEAR}-03-21" "${YEAR}-06-20"
;;
"09")
set_environment_variables_for_season ${SEASONS[$MONTH]} "${YEAR}-06-21" "${YEAR}-09-20"
;;
"12")
set_environment_variables_for_season ${SEASONS[$MONTH]} "${YEAR}-09-21" "${YEAR}-12-20"
;;
*)
echo "Invalid month: $MONTH" >&2
exit 1
;;
esac
- name: Write metadata post
uses: ./
with:
github-username: library-pals
github-repository: sample-site
source-bookmarks: recipes|_data/recipes.json
book-tags: "recommend,skip"
start-date: ${{ steps.set-season.outputs.START_DATE }}
end-date: ${{ steps.set-season.outputs.END_DATE }}
post-title: ${{ steps.set-season.outputs.POST_TITLE }}
env:
TOKEN: ${{ secrets.TOKEN }}
- name: Commit files
run: |
git pull
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add -A && git commit -m "${{steps.set-season.outputs.SEASON_EMOJI}} ${{ steps.set-season.outputs.POST_TITLE }}"
git push