generated from Flashky/advent-of-code-yyyy
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (76 loc) · 3.71 KB
/
update-year.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f
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 }}"