02 Maintain: Update Workflow Files #120
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: "02 Maintain: Update Workflow Files" | |
on: | |
workflow_dispatch: | |
inputs: | |
name: | |
description: 'Who triggered this build (enter github username to tag yourself)?' | |
required: true | |
default: 'weekly run' | |
clean: | |
description: 'Workflow files/file extensions to clean (no wildcards, enter "" for none)' | |
required: false | |
default: '.yaml' | |
schedule: | |
# Run every Tuesday | |
- cron: '0 0 * * 2' | |
jobs: | |
check_token: | |
name: "Check SANDPAPER_WORKFLOW token" | |
runs-on: ubuntu-latest | |
outputs: | |
workflow: ${{ steps.validate.outputs.wf }} | |
repo: ${{ steps.validate.outputs.repo }} | |
steps: | |
- name: "validate token" | |
id: validate | |
uses: carpentries/actions/check-valid-credentials@main | |
with: | |
token: ${{ secrets.SANDPAPER_WORKFLOW }} | |
bad_token: | |
name: "Invalid/Missing Token" | |
runs-on: ubuntu-latest | |
needs: check_token | |
if: ${{ needs.check_token.outputs.workflow != 'true' }} | |
steps: | |
- name: "Instructions to create a new token" | |
run: | | |
printf "::warning::The SANDPAPER_WORKFLOW token workflow scope is not valid\n"\ | |
"If you want to have periodic pull request updates, you will need to generate a new token by going to "\ | |
"https://github.com/settings/tokens/new?scopes=repo,workflow&description=Sandpaper%%20Token%%20%%28${{ github.repository }}%%29\n"\ | |
"Once you have created the token, copy it to your clipboard and go to "\ | |
"https://github.com/${{ github.repository }}/settings/secrets/actions/new "\ | |
"and enter SANDPAPER_WORKFLOW for the 'Name' and paste your key for the 'Value'." | |
update_workflow: | |
name: "Update Workflow" | |
runs-on: ubuntu-latest | |
needs: check_token | |
if: ${{ needs.check_token.outputs.workflow == 'true' }} | |
steps: | |
- name: "Checkout Repository" | |
uses: actions/checkout@v2 | |
- name: Update Workflows | |
id: update | |
uses: carpentries/actions/update-workflows@main | |
with: | |
clean: ${{ github.event.inputs.clean }} | |
- name: Create Pull Request | |
id: cpr | |
if: "${{ steps.update.outputs.new }}" | |
uses: peter-evans/create-pull-request@v3.10.0 | |
with: | |
token: ${{ secrets.SANDPAPER_WORKFLOW }} | |
delete-branch: true | |
branch: "update-workflows-version-${{ steps.update.outputs.new }}" | |
commit-message: "[actions] update sandpaper workflow to version ${{ steps.update.outputs.new }}" | |
title: "Update Workflows to Version ${{ steps.update.outputs.new }}" | |
body: | | |
:robot: This is an automated build | |
Update Workflows from sandpaper version ${{ steps.update.outputs.old }} -> ${{ steps.update.outputs.new }} | |
- Auto-generated by [create-pull-request][1] via ${{ github.event.inputs.name }} | |
[1]: https://github.com/peter-evans/create-pull-request | |
labels: "type:template and tools" | |
draft: false |