Daily Tag Creator #24
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
name: Daily Tag Creator | |
on: | |
schedule: | |
- cron: '00 18 * * *' # This cron expression runs at 11:30 PM IST (which is 18:00 UTC) | |
jobs: | |
create-daily-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Ensure full history is fetched for logging | |
- name: Set up Date Command | |
run: sudo apt-get install -y tzdata | |
- name: Get the current date in IST | |
id: date | |
run: | | |
DATE=$(TZ='Asia/Kolkata' date +'%d-%m-%Y') || { echo "Failed to get date"; exit 1; } | |
echo "Current date in IST: $DATE" | |
echo "DATE=$DATE" >> $GITHUB_ENV | |
continue-on-error: false | |
- name: Check for commits today | |
id: commits | |
run: | | |
COMMITS=$(git log --since=midnight --until=now --oneline || { echo "Failed to check commits"; exit 1; }) | |
echo "Commits today: $COMMITS" | |
if [ -z "$COMMITS" ]; then | |
echo "No commits found today" | |
echo "HAS_COMMITS=false" >> $GITHUB_ENV | |
else | |
echo "Commits found" | |
echo "HAS_COMMITS=true" >> $GITHUB_ENV | |
fi | |
continue-on-error: false | |
- name: Create Tag | |
if: env.HAS_COMMITS == 'true' | |
env: | |
TAG_DATE: ${{ env.DATE }} | |
run: | | |
echo "Creating tag $TAG_DATE" | |
git config --global user.name "github-actions[bot]" || { echo "Failed to configure git user name"; exit 1; } | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" || { echo "Failed to configure git user email"; exit 1; } | |
git tag $TAG_DATE || { echo "Failed to create tag"; exit 1; } | |
git push origin $TAG_DATE || { echo "Failed to push tag"; exit 1; } | |
continue-on-error: false | |
- name: Log success message | |
if: success() | |
run: echo "Workflow completed successfully" | |
- name: Log failure message | |
if: failure() | |
run: echo "Workflow failed" |