From 3898edd39af1de2986fd2e1fa89052de46761339 Mon Sep 17 00:00:00 2001 From: Katy DeCorah Date: Wed, 19 Jun 2024 20:20:04 -0400 Subject: [PATCH] Update metadata-advanced.yml --- .github/workflows/metadata-advanced.yml | 41 +++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/metadata-advanced.yml b/.github/workflows/metadata-advanced.yml index 5b95e6d..0cf94f4 100644 --- a/.github/workflows/metadata-advanced.yml +++ b/.github/workflows/metadata-advanced.yml @@ -17,10 +17,13 @@ jobs: - 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" @@ -28,7 +31,15 @@ jobs: ["12"]="Fall" ) - set_env_vars() { + 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 @@ -40,23 +51,29 @@ jobs: post_title="${YEAR} ${season}" fi - echo "POST_TITLE=${post_title}" >> $GITHUB_ENV - echo "START_DATE=${start_date}" >> $GITHUB_ENV - echo "END_DATE=${end_date}" >> $GITHUB_ENV + 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_env_vars ${SEASONS[$MONTH]} "$(($YEAR - 1))-12-21" "${YEAR}-03-20" + set_environment_variables_for_season ${SEASONS[$MONTH]} "$(($YEAR - 1))-12-21" "${YEAR}-03-20" ;; "06") - set_env_vars ${SEASONS[$MONTH]} "${YEAR}-03-21" "${YEAR}-06-20" + set_environment_variables_for_season ${SEASONS[$MONTH]} "${YEAR}-03-21" "${YEAR}-06-20" ;; "09") - set_env_vars ${SEASONS[$MONTH]} "${YEAR}-06-21" "${YEAR}-09-20" + set_environment_variables_for_season ${SEASONS[$MONTH]} "${YEAR}-06-21" "${YEAR}-09-20" ;; "12") - set_env_vars ${SEASONS[$MONTH]} "${YEAR}-09-21" "${YEAR}-12-20" + 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 @@ -66,9 +83,9 @@ jobs: github-repository: sample-site source-bookmarks: recipes|_data/recipes.json book-tags: "recommend,skip" - start-date: ${{ env.START_DATE }} - end-date: ${{ env.END_DATE }} - post-title: ${{ env.POST_TITLE }} + 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 @@ -76,5 +93,5 @@ jobs: git pull git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git add -A && git commit -m "${{ env.POST_TITLE }}" + git add -A && git commit -m "${{steps.set-season.outputs.SEASON_EMOJI}} ${{ steps.set-season.outputs.POST_TITLE }}" git push