Skip to content

Kotlin template auto-generator #21

Kotlin template auto-generator

Kotlin template auto-generator #21

name: Kotlin template auto-generator
on:
schedule:
- cron: "0 18 * * *"
workflow_dispatch:
jobs:
setup-day:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Git
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
- name: Calculate Next Day
id: day
run: |
TODAY=$(date -u +"%Y-%m-%d")
CURRENT_DAY=$(date -u -d "$TODAY" +%-d)
NEXT_DAY=$((CURRENT_DAY + 1))
if [ "$NEXT_DAY" -gt 25 ]; then
echo "delete=true" >> $GITHUB_ENV
exit 0
fi
echo "delete=false" >> $GITHUB_ENV
echo "DAY=$(printf '%02d' $NEXT_DAY)" >> $GITHUB_ENV
- name: Generate folders and copy templates
if: env.delete == 'false'
run: |
DAY_FOLDER="2024/kotlin/src/main/kotlin/com/tymscar/day${{ env.DAY }}"
mkdir -p "$DAY_FOLDER/part1" "$DAY_FOLDER/part2"
cp templates/kotlin/day.kt "$DAY_FOLDER/day${{ env.DAY }}.kt"
cp templates/kotlin/part1/part1.kt "$DAY_FOLDER/part1/part1.kt"
cp templates/kotlin/part2/part2.kt "$DAY_FOLDER/part2/part2.kt"
sed -i "s/{{DAY}}/${{ env.DAY }}/g" "$DAY_FOLDER/day${{ env.DAY }}.kt"
sed -i "s/{{DAY}}/${{ env.DAY }}/g" "$DAY_FOLDER/part1/part1.kt"
sed -i "s/{{DAY}}/${{ env.DAY }}/g" "$DAY_FOLDER/part2/part2.kt"
git add .
git commit -m "Setup files for Day ${{ env.DAY }}"
git push
- name: Delete workflow if past December 25
if: env.delete == 'true'
run: |
rm -rf templates
rm -f .github/workflows/kotlin-template.yaml
git add templates .github/workflows/kotlin-template.yaml
git commit -m "Kotlin template generator removed"
git push