Skip to content

Create or update branch and pull request from APG trigger #74

Create or update branch and pull request from APG trigger

Create or update branch and pull request from APG trigger #74

Workflow file for this run

name: Create or update branch and pull request from APG trigger
on:
workflow_dispatch:
inputs:
apg_branch:
description: 'Name of branch to be created'
required: true
apg_sha:
description: 'Commit SHA to look for from source'
required: true
apg_pr_number:
description: 'PR number from aria-practices that triggered this workflow'
required: true
fork_path:
description: 'Available when the triggering PR is from a fork'
required: false
jobs:
create-pr:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Get current job and log url
uses: Tiryoh/gha-jobid-action@v0
id: jobs
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
job_name: create-pr
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
cache: npm
cache-dependency-path: scripts/pre-build/package-lock.json
- name: Set up Ruby 2.6.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6.2
- name: Update git submodules
if: github.event.inputs.fork_path == 'false'
run: |
git submodule update --recursive --remote
cd _external/aria-practices
git checkout ${{ github.event.inputs.apg_sha }}
- name: Update git submodules from fork
if: github.event.inputs.fork_path != 'false'
run: |
git submodule update --recursive --remote
cd _external/aria-practices
git remote add fork https://github.com/${{ github.event.inputs.fork_path }}.git
git fetch fork
git checkout ${{ github.event.inputs.apg_sha }}
- name: Switch to and create/update branch
run: |
# switch to branch if exists or create branch
git switch apg/${{ github.event.inputs.apg_branch }} 2>/dev/null || git switch -c apg/${{ github.event.inputs.apg_branch }}
- name: Update site files
id: update_site_files
working-directory: ./
run: |
bundle install
npm install -C scripts/pre-build
node ./scripts/pre-build
continue-on-error: true
# - name: Commit changed files and submodule updates
# if: steps.update_site_files.outcome == 'success'
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_message: Commit changed files and submodule updates
# branch: apg/${{ github.event.inputs.apg_branch }}
# commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
# push_options: '--force'
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Pull Request
if: steps.update_site_files.outcome == 'success'
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Commit changed files and submodule updates
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
branch: apg/${{ github.event.inputs.apg_branch }}
title: apg/${{ github.event.inputs.apg_branch }} generated by aria-practices
body: Generated by ${{ github.repository_owner }}/aria-practices#${{ github.event.inputs.apg_pr_number }}
draft: true
- name: Create pull request
if: ${{ steps.cpr.outputs.pull-request-number }}
working-directory: ./
run: |
npm install -C scripts/create-pr
node ./scripts/create-pr
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
APG_SHA: ${{ github.event.inputs.apg_sha }}
APG_BRANCH: ${{ github.event.inputs.apg_branch }}
APG_PR_NUMBER: ${{ github.event.inputs.apg_pr_number }}
REPO_OWNER: ${{ github.repository_owner }}
OUTCOME: ${{ steps.update_site_files.outcome }}
JOB_ID: ${{ steps.jobs.outputs.job_id }}
WAI_PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}