-
Notifications
You must be signed in to change notification settings - Fork 25
106 lines (85 loc) · 2.86 KB
/
createPullRequest.yml
File metadata and controls
106 lines (85 loc) · 2.86 KB
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
name: Create new version pull request
on:
push:
branches:
- 'v*'
permissions:
contents: read
pull-requests: write
jobs:
check-branch-name:
name: Check branch name
if: github.repository == 'adjust/web_sdk'
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.gate.outputs.skip }}
steps:
- uses: actions/checkout@v4
- name: Branch must match VERSION
id: gate
shell: bash
run: |
# Enable strict bash mode:
# -e - exit immediately if any command fails
# -u - treat unset variables as an error
# -o pipefail - fail the script if any command in a pipeline fails
set -euo pipefail
BRANCH="${{ github.ref_name }}"
VERSION="$(tr -d ' \t\r\n' < VERSION)"
EXPECTED="v$VERSION"
if [[ "$BRANCH" != "$EXPECTED" ]]; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Skipping: branch '$BRANCH' != '$EXPECTED' (from VERSION)."
exit 0
fi
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "OK: branch matches VERSION ($BRANCH)."
create-pull-request:
name: Create pull request
needs: [check-branch-name]
if: needs.check-branch-name.outputs.skip != 'true' && github.repository == 'adjust/web_sdk'
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Create PR (idempotent)
shell: bash
run: |
set -euo pipefail
BRANCH="${{ github.ref_name }}"
BASE="master"
TITLE="Bump version to $BRANCH"
# If PR already exists for this head/base, do nothing.
count=$(gh pr list -B "$BASE" -H "$BRANCH" --json number --jq 'length')
if (( count > 0 )); then
echo "Pull request already exists. Skipping without failing."
exit 0
fi
gh pr create -B "$BASE" -H "$BRANCH" --title "$TITLE" --body ""
echo "Pull request successfully created."
check-dist-is-up-to-date:
name: Check dist is up to date
needs: [check-branch-name, create-pull-request]
if: always() && needs.check-branch-name.outputs.skip != 'true' && github.repository == 'adjust/web_sdk'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.19.2'
check-latest: true
cache: "npm"
- name: Verify dist is up to date
shell: bash
run: |
set -euo pipefail
npm ci
npm run build
if git status --porcelain -- dist/ | grep -q .; then
echo "ERROR: npm run build produced changes in dist/:"
git status --porcelain -- dist/
exit 1
fi
echo "OK: dist/ is up to date."