Update tabi theme #3
This file contains hidden or 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
name: Update tabi theme | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "5 0 * * 1" # Weekly on Mondays at 5 past midnight UTC | |
jobs: | |
update-tabi: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Configure Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
- name: Check for updates | |
id: check | |
run: | | |
cd themes/tabi | |
CURRENT=$(git rev-parse HEAD) | |
git fetch | |
git checkout origin/main | |
NEW=$(git rev-parse HEAD) | |
if [ "$CURRENT" != "$NEW" ]; then | |
# Get main changelog | |
MAIN_CHANGELOG=$(git log --pretty=format:'- %s [%h](https://github.com/welpo/tabi/commit/%H)' $CURRENT..$NEW | \ | |
grep -v -E '^- .*(misc|misc\([^)]+\)):' | \ | |
sed -E 's/#([0-9]+)/[#\1](https:\/\/github.com\/welpo\/tabi\/pull\/\1)/g') | |
# Get misc changelog | |
MISC_CHANGELOG=$(git log --pretty=format:'- %s [%h](https://github.com/welpo/tabi/commit/%H)' $CURRENT..$NEW | \ | |
grep -E '^- .*(misc|misc\([^)]+\)):' | \ | |
sed -E 's/#([0-9]+)/[#\1](https:\/\/github.com\/welpo\/tabi\/pull\/\1)/g') | |
echo "has_changes=true" >> "$GITHUB_OUTPUT" | |
echo "old_version=${CURRENT:0:7}" >> "$GITHUB_OUTPUT" | |
echo "new_version=${NEW:0:7}" >> "$GITHUB_OUTPUT" | |
echo "main_changelog<<CHANGELOG_DELIMITER" >> "$GITHUB_OUTPUT" | |
echo "$MAIN_CHANGELOG" >> "$GITHUB_OUTPUT" | |
echo "CHANGELOG_DELIMITER" >> "$GITHUB_OUTPUT" | |
echo "misc_changelog<<MISC_DELIMITER" >> "$GITHUB_OUTPUT" | |
echo "$MISC_CHANGELOG" >> "$GITHUB_OUTPUT" | |
echo "MISC_DELIMITER" >> "$GITHUB_OUTPUT" | |
fi | |
cd ../.. | |
- name: Create Pull Request | |
if: steps.check.outputs.has_changes == 'true' | |
run: | | |
# Create branch | |
BRANCH="update-tabi-$(date +%Y%m%d-%H%M%S)" | |
git checkout -b "$BRANCH" | |
# Commit changes | |
git add themes/tabi | |
git commit -m "⬆️ Update tabi | |
From: ${{ steps.check.outputs.old_version }} | |
To: ${{ steps.check.outputs.new_version }} | |
Update tabi to the latest version from https://github.com/welpo/tabi" | |
git push origin "$BRANCH" | |
# Write PR body to file | |
cat > pr_body.md << 'EOF' | |
## Changes in this update | |
Updating `themes/tabi` from [`${{ steps.check.outputs.old_version }}`](https://github.com/welpo/tabi/commit/${{ steps.check.outputs.old_version }}) to [`${{ steps.check.outputs.new_version }}`](https://github.com/welpo/tabi/commit/${{ steps.check.outputs.new_version }}). | |
### Changelog | |
${{ steps.check.outputs.main_changelog }} | |
EOF | |
if [ ! -z "${{ steps.check.outputs.misc_changelog }}" ]; then | |
cat >> pr_body.md << 'EOF' | |
<details> | |
<summary>Show/hide miscellaneous changes</summary> | |
${{ steps.check.outputs.misc_changelog }} | |
</details> | |
EOF | |
fi | |
# Add footer | |
cat >> pr_body.md << 'EOF' | |
--- | |
Auto-generated by the "Update tabi theme" workflow (in `.github/workflows/update-tabi.yml`). | |
EOF | |
gh pr create \ | |
--head "$BRANCH" \ | |
--title "⬆️ Update tabi theme to ${{ steps.check.outputs.new_version }}" \ | |
--body-file pr_body.md | |
rm pr_body.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |