Update Graypaper #102
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: Update Graypaper | |
on: | |
push: | |
branches: | |
- 'feature/auto-update-workflow' | |
workflow_dispatch: | |
schedule: | |
- cron: "51 13 * * *" # using an arbitrary time to avoid high traffic | |
jobs: | |
check_for_updates: | |
name: Check for updates | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
outputs: | |
has_updates: ${{steps.remote_release.outputs.VERSION != steps.local_release.outputs.VERSION}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: What's the latest graypaper-archive version? | |
id: remote_release | |
run: | | |
REMOTE_TAG=$(set -eo pipefail && gh api /repos/FluffyLabs/graypaper-archive/releases/latest | jq -r '.tag_name') | |
echo "VERSION=$REMOTE_TAG" >> "$GITHUB_OUTPUT" | |
echo "The remote version is $REMOTE_TAG" | |
- name: What's the version we're using? | |
id: local_release | |
run: | | |
cd graypaper-archive | |
git fetch --tags | |
LOCAL_TAG=$(git describe --tags) | |
echo "VERSION=$LOCAL_TAG" >> "$GITHUB_OUTPUT" | |
echo "The local version is $LOCAL_TAG" | |
update: | |
name: Update | |
runs-on: ubuntu-latest | |
needs: check_for_updates | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
GH_TOKEN: ${{ github.token }} | |
if: needs.check_for_updates.outputs.has_updates == 'true' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: Get the latest graypaper-archive | |
id: archive_update | |
run: | | |
cd graypaper-archive | |
git fetch --tags | |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
git checkout $LATEST_TAG | |
echo "VERSION=$LATEST_TAG" >> "$GITHUB_OUTPUT" | |
echo "TAG_NAME=$(date +\"%Y-%m-%d\")" >> "$GITHUB_OUTPUT" | |
cd .. | |
- name: Use git as github actions bot | |
run: | | |
BOT_NAME="github-actions[bot]" | |
BOT_EMAIL="$(gh api /users/github-actions[bot] | jq -r '.id')+$BOT_NAME@users.noreply.github.com" | |
git config --global user.name $BOT_NAME | |
git config --global user.email $BOT_EMAIL | |
- name: Create a PR and merge changes to the main branch | |
run: | | |
BRANCH_NAME="feature/gp-bump-${{steps.archive_update.outputs.VERSION}}" | |
git checkout -b $BRANCH_NAME | |
git add . | |
git commit -m "Bumped Graypaper to ${{steps.archive_update.outputs.VERSION}}" | |
git push --set-upstream origin $BRANCH_NAME | |
gh pr create -B main -H $BRANCH_NAME \ | |
--title "Bump Graypaper to ${{steps.archive_update.outputs.VERSION}}" --body "" | |
gh pr merge --rebase --delete-branch | |
- name: Create Release | |
run: | | |
gh release create --draft ${{ steps.archive_update.outputs.TAG_NAME }} \ | |
-t "Release ${{ steps.archive_update.outputs.TAG_NAME }}" \ | |
-n "Bumped Graypaper version to ${{steps.archive_update.outputs.VERSION}}" |