Skip to content

Update year

Update year #1

Workflow file for this run

name: Update year
on:
workflow_dispatch:
inputs:
aoc_year:
description: 'Advent of Code year'
required: true
default: 'yyyy'
jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Check Repository
run: |
if [ "${{ github.repository }}" == "Flashky/advent-of-code-yyyy" ]; then
echo -e "\e[91mError: This workflow cannot be run from the template repository.\e[0m"
exit 1
fi
- name: Check for Token Secret
run: |
if [ -z "${{ secrets.PAT_TOKEN }}" ]; then
echo -e "\e[91mError: PAT_TOKEN secret is not set.\e[0m"
echo -e "\e[93mTo generate a personal access token (PAT) for GitHub Actions:\e[0m"
echo -e "\e[93m1. Go to \e[94mhttps://github.com/settings/tokens\e[0m"
echo -e "\e[93m2. Click on \e[92mGenerate new token\e[0m\e[93m and then on \e[92mGenerate new token (classic) \e[0m\e[93m\e[0m"
echo -e "\e[93m3. Give your token a name, select the required scopes (e.g., repo), and click on \e[92mGenerate token\e[93m\e[0m"
echo -e "\e[93m4. Copy the generated token"
echo -e "\e[93m5. Go to your repository on GitHub -> Settings -> Secrets -> New repository secret"
echo -e "\e[93m6. Name the secret \e[94mPAT_TOKEN\e[93m and paste the copied token as the value"
exit 1
fi
- name: Check Year Format
run: |
if echo "${{ github.event.inputs.aoc_year }}" | grep -E -q '^[0-9]{4}$'; then
echo "Year '${{ github.event.inputs.aoc_year }}' format is valid."
else
echo -e "\e[91mError: Invalid year format ('${{ github.event.inputs.aoc_year }}'). Please provide a valid 4-digit year.\e[0m"
exit 1
fi
update:
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Repository Description
run: |
token="${{ secrets.PAT_TOKEN }}"
url=https://api.github.com/repos/${{ github.repository }}
description='{"description": "Advent of Code ${{ github.event.inputs.aoc_year }}"}'
curl -X PATCH -H "Authorization: Bearer $token" -H "Accept: application/vnd.github.v3+json" -d "$description" $url
- name: Update Repository Topics
run: |
token="${{ secrets.PAT_TOKEN }}"
url="https://api.github.com/repos/${{ github.repository }}/topics"
topics='{"names": ["java", "advent-of-code", "advent-of-code-${{ github.event.inputs.aoc_year }}", "advent-of-code-${{ github.event.inputs.aoc_year }}-java"]}'
curl -X PUT -H "Authorization: Bearer $token" -H "Accept: application/vnd.github.mercy-preview+json" -d "$topics" $url
- name: Update README.md
run: |
find . -name 'README.md' | xargs sed -i 's/{year}/'${{ github.event.inputs.aoc_year }}'/g'
- name: Update pom.xml
run: |
find . -name 'pom.xml' | xargs sed -i 's/yyyy/'${{ github.event.inputs.aoc_year }}'/g'
- name: Open Pull Request
uses: peter-evans/create-pull-request@v7
id: pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update year to ${{ github.event.inputs.aoc_year }}"
title: "Update year to ${{ github.event.inputs.aoc_year }}"
body: |
This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
- name: Check PR information
if: ${{ steps.pull-request.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.pull-request.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.pull-request.outputs.pull-request-url }}"