-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create kotlin template generator GHA
- Loading branch information
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.tymscar.day{{DAY}} | ||
|
||
import java.io.File | ||
import com.tymscar.day{{DAY}}.part1.solve as part1 | ||
import com.tymscar.day{{DAY}}.part2.solve as part2 | ||
|
||
fun solve() { | ||
var input: String = File("src/main/kotlin/com/tymscar/day{{DAY}}/input.txt").readText() | ||
|
||
println("Day {{DAY}}: ") | ||
println("Part 1: ${part1(input)}") | ||
println("Part 2: ${part2(input)}") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.tymscar.day{{DAY}}.part1 | ||
|
||
fun solve(input: String): String { | ||
return input | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.tymscar.day{{DAY}}.part2 | ||
|
||
fun solve(input: String): String { | ||
return input | ||
} |