generated from w3c/wai-resource-template
-
Notifications
You must be signed in to change notification settings - Fork 14
136 lines (118 loc) · 4.83 KB
/
pr-create.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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:
pr-create:
runs-on: ubuntu-latest
steps:
- name: Get current job and log url
uses: Tiryoh/gha-jobid-action@v1
id: jobs
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
job_name: pr-create
- 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 3.3
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: Update git submodules
run: |
git submodule update --recursive --remote
cd _external/aria-practices
if [ -n "${{ github.event.inputs.fork_path }}" ] && [ "${{ github.event.inputs.fork_path }}" != 'false' ]; then
echo "Found fork: ${{ github.event.inputs.fork_path }}"
git remote add fork https://github.com/${{ github.event.inputs.fork_path }}.git
git fetch fork
fi
git checkout ${{ github.event.inputs.apg_sha }}
- name: Switch to and create or 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: Force rebase the switched branch onto main
run: |
git config --global user.name "w3cgruntbot"
git config --global user.email "[email protected]"
git fetch origin main
git rebase --force-rebase origin/main
# Handle cases where the aria-practices submodule has conflicts to be handled;
# _external/data shouldn't have conflicting changes
if [ -d "_external/aria-practices" ] && { [ -f ".git/rebase-apply" ] || [ -d ".git/rebase-merge" ]; }; then
echo "Handling submodule conflicts..."
cd _external/aria-practices
# Resolve the conflict
git fetch origin
git merge origin/main
# Add resolved submodule from project root
cd -
git add _external/aria-practices
# Continue the rebase
git rebase --continue
# Resolve conflicts for all other conflicting files automatically using 'theirs' from project root
git diff --name-only --diff-filter=U | while read -r file; do
git checkout --theirs "$file"
git add "$file"
done
# Continue the rebase
git rebase --continue || true # Suppress the error with true if nothing additional
else
echo "No submodule conflicts detected or no rebase in progress."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- 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_user_name: w3cgruntbot
commit_user_email: [email protected]
commit_author: w3cgruntbot <[email protected]>
commit_message: 'chore: Update branch with latest `${{ github.event.inputs.apg_branch }}` changes and submodule updates'
branch: apg/${{ github.event.inputs.apg_branch }}
push_options: '--force'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create or update pull request
working-directory: ./
run: |
set -e
npm install -C scripts/pr-create
node ./scripts/pr-create
env:
GH_TOKEN: ${{ secrets.W3CGRUNTBOT_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 }}