Skip to content

Commit

Permalink
Add schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Jan 8, 2025
1 parent 17bf50c commit 8191013
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
name: Release Every Other Monday
on:
workflow_dispatch:
# Run action at 16:15 PM on Monday (UTC)
# schedule:
# @TODO: the schedule below is weekly. Do byweekly check.
# - cron: '15 16 * * 1'
schedule:
# At 10AM EST Monday
- cron: '0 15 * * 1'

# Sets the GITHUB_TOKEN permissions to allow release
permissions:
contents: write
env:
# Solutions is from https://github.com/wham/bi-weekly-action/blob/main/.github/workflows/bi-weekly-action.yml
# The date of the first run of the action. It has to be set to a date that is on the same weekday as the cron.
FIRST_RUN_DATE: 2025-01-06

# This action requires a GitHub app with content write access installed
# to bypass the main branch protection rule and dispatch the event to a different repo

jobs:
weekindex:
runs-on: ubuntu-latest
outputs:
weekindex: ${{ steps.calculate.outputs.weekindex }}
steps:
- name: Calculate weekdiff
id: calculate
run: |
current_date=$(date +%Y-%m-%d)
start=$(date -d ${{ env.FIRST_RUN_DATE }} +%s)
end=$(date -d $current_date +%s)
weekdiff=$(((end-start) / 60 / 60 / 24 / 7))
weekindex=$((weekdiff % 2))
echo "weekindex=$weekindex" >> "$GITHUB_OUTPUT"
echo "FIRST_RUN_DATE: ${{ env.FIRST_RUN_DATE }}" >> $GITHUB_STEP_SUMMARY
echo "current_date: $current_date" >> $GITHUB_STEP_SUMMARY
echo "weekdiff: $weekdiff" >> $GITHUB_STEP_SUMMARY
echo "weekindex: $weekindex" >> $GITHUB_STEP_SUMMARY
if [ $weekindex -eq 0 ]; then
echo "🟢 The week index is 0. The action is going to run." >> $GITHUB_STEP_SUMMARY
else
echo "🔴 The week index is 1. The action is going to be skipped." >> $GITHUB_STEP_SUMMARY
fi
release:
if: ${{ needs.weekindex.outputs.weekindex == 0 }}
runs-on: ubuntu-latest
needs:
- weekindex
steps:
- name: Generate a token
id: generate-token
Expand Down

0 comments on commit 8191013

Please sign in to comment.