Check for new Hugo versions #668
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
name: Check for new Hugo versions | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: 0 0 * * 1,3,5 | |
jobs: | |
hugo-updates: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check for new hugo version | |
id: versions | |
run: | | |
NEW=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r .name) | |
wget https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$GITHUB_SHA/.hugoversion | |
OLD=$(cat .hugoversion) | |
echo "::set-output name=new::$NEW" | |
echo "::set-output name=old::$OLD" | |
echo "$OLD == $NEW" | |
- name: Checkout repo | |
if: steps.versions.outputs.new != steps.versions.outputs.old | |
uses: actions/checkout@v2 | |
with: | |
submodules: true | |
ref: master | |
- name: Modify .hugoversion | |
if: steps.versions.outputs.new != steps.versions.outputs.old | |
env: | |
VERSION: ${{ steps.versions.outputs.new }} | |
run: | | |
echo -ne $VERSION > .hugoversion | |
- name: Get hugo release notes | |
id: release | |
if: steps.versions.outputs.new != steps.versions.outputs.old | |
env: | |
VERSION: ${{ steps.versions.outputs.new }} | |
run: | | |
RELEASE_NOTES="$( | |
curl -s https://api.github.com/repos/gohugoio/hugo/releases \ | |
| jq -r --arg version $VERSION \ | |
'.[] | select(.tag_name == $version) | .body' | |
)" | |
# Escape \n, \r and % | |
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}" | |
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}" | |
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}" | |
echo "::set-output name=notes::$RELEASE_NOTES" | |
- name: Generate token for Pull Request | |
id: generate-token | |
uses: tibdex/github-app-token@v1 | |
if: steps.versions.outputs.new != steps.versions.outputs.old | |
with: | |
app_id: ${{ secrets.PR_APP_ID }} | |
private_key: ${{ secrets.PR_APP_PRIVATE_KEY }} | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v3 | |
if: steps.versions.outputs.new != steps.versions.outputs.old | |
with: | |
token: ${{ steps.generate-token.outputs.token }} | |
labels: test-for-regression | |
branch: hugo-${{ steps.versions.outputs.new }} | |
commit-message: Update Hugo to ${{ steps.versions.outputs.new }} | |
title: Update Hugo to ${{ steps.versions.outputs.new }} | |
body: | | |
:crown: Hugo update! | |
# ${{ steps.versions.outputs.new }} Release Notes | |
${{ steps.release.outputs.notes }} |