-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow for upgrading locales to next year
Schedule workflow to run on 1st of August of each year * Calculate data for all present locales for the next year * Add news item to website * Build and deploy page after upgrade
- Loading branch information
Showing
1 changed file
with
166 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,166 @@ | ||
name: Upgrade year | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 1 8 *' | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
upgrade-year: | ||
runs-on: ubuntu-latest | ||
concurrency: | ||
group: "update-locales" | ||
cancel-in-progress: false | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Determine next year | ||
id: get-next-year | ||
run: | | ||
current_year=$( date +'%Y' ) | ||
echo "year=$(( current_year + 1 ))" >> "${GITHUB_OUTPUT}" | ||
- name: Set up Python environment | ||
run: | | ||
python -m venv /tmp/venv | ||
/tmp/venv/bin/pip install --upgrade pip | ||
/tmp/venv/bin/pip install holidata | ||
- name: Upgrade locales years | ||
id: upgrade-year | ||
run: | | ||
year="${{ steps.get-next-year.outputs.year }}" | ||
formats=( "json" "yaml" "xml" "csv" ) | ||
for locale_dir in holidata/??-?? ; do | ||
locale="${locale_dir/holidata\//}" | ||
echo "Generating locale '${locale}' files for ${year}..." | ||
for format in "${formats[@]}" ; do | ||
echo "Generating ${locale}/${year}.${format}" | ||
/tmp/venv/bin/holidata --year="${year}" --locale="${locale}" --output="${format}" > "${locale_dir}/${year}.${format}" | ||
done | ||
echo "Generated locale ${locale} for year ${year}" | ||
echo "${locale##*-}" >> /tmp/countries | ||
done | ||
sort -u < /tmp/countries > /tmp/sorted | ||
countries="$( paste -s -d, /tmp/sorted )" | ||
echo "countries=${countries//,/, }" >> "${GITHUB_OUTPUT}" | ||
current_date="$( date +'%Y-%m-%d' )" | ||
cat <<EOF > "content/news/${current_date}-holidata-${year}.md" | ||
--- | ||
title: "Holidata for ${year} available" | ||
date: ${current_date}T00:00:00+02:00 | ||
layout: "news_item" | ||
--- | ||
The holidata for ${year} is now available for all locales! | ||
<!--more--> | ||
We have published the holiday data set for ${year}. | ||
The holiday data is currently available for $( wc -l /tmp/sorted | awk '{print $1}' ) countries. | ||
> ⚠️ Note that depending on the country, the data might not yet be complete or correct, as the legislature will update their holiday calendar in the next months. | ||
See [here](https://github.com/GothenburgBitFactory/holidata) on how you can contribute to updating/adding more locales! | ||
If you spot an error, please report it [here](https://github.com/GothenburgBitFactory/holidata/issues/new?labels=bug&template=bug_report.md&title=Error+in+locale+LOCALE%5B%2C+year+YEAR%5D). | ||
EOF | ||
continue-on-error: false | ||
|
||
- name: Create Pull Request | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
delete-branch: true | ||
commit-message: | | ||
Added locale files for year ${{ steps.get-next-year.outputs.year }} | ||
Added locale files for year ${{ steps.get-next-year.outputs.year }} of countries ${{ steps.upgrade-year.outputs.countries }}. | ||
author: "Holidata Bot <[email protected]>" | ||
title: Added locale files for year ${{ steps.get-next-year.outputs.year }} | ||
body: | | ||
Added locale files for year ${{ steps.get-next-year.outputs.year }} of countries ${{ steps.upgrade-year.outputs.countries }}. | ||
Auto-generated by [create-pull-request][1] | ||
[1]: https://github.com/peter-evans/create-pull-request | ||
branch: upgrade-year | ||
|
||
- name: Merge Pull Request | ||
if: "${{ steps.cpr.outputs.pull-request-number != '' }}" | ||
uses: juliangruber/merge-pull-request-action@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
number: ${{ steps.cpr.outputs.pull-request-number }} | ||
method: rebase | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
needs: upgrade-year | ||
environment: github-pages | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
steps: | ||
- name: Install Hugo CLI | ||
run: | | ||
echo "Installing Hugo v${{ vars.HUGO_VERSION }}" | ||
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${{ vars.HUGO_VERSION }}/hugo_extended_${{ vars.HUGO_VERSION }}_linux-amd64.deb \ | ||
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb | ||
- name: Install Dart Sass | ||
run: sudo snap install dart-sass | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: "main" | ||
submodules: recursive | ||
|
||
- name: Setup Pages | ||
id: pages | ||
uses: actions/configure-pages@v5 | ||
|
||
- name: Install Node.js dependencies | ||
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" | ||
|
||
- name: Build with Hugo | ||
env: | ||
# For maximum backward compatibility with Hugo modules | ||
HUGO_ENVIRONMENT: production | ||
HUGO_ENV: production | ||
run: | | ||
hugo \ | ||
--minify \ | ||
--baseURL "${{ steps.pages.outputs.base_url }}/" | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: ./html | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |