Repository navigation
115 lines (101 loc) · 4.67 KB
/
Copy pathrelease.yml
File metadata and controls
115 lines (101 loc) · 4.67 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
107
108
109
110
111
112
113
114
115
name: Release
# Publishes via npm trusted publishing (OIDC) — no npm token. Each package's trusted
# publisher on npmjs.com must name this exact file: release.yml.
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: write
id-token: write
pull-requests: write
actions: write
env:
YARN_ENABLE_HARDENED_MODE: "1"
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Checkout malware scanner
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
repository: ChurchApps/.github
ref: main
path: .polinrider
persist-credentials: false
# Step 1: the PolinRider malware scan. The scanner runs from outside the
# tree and is removed from it before scanning. A finding fails this step
# and nothing below it runs.
- name: Malware scan
run: |
cp .polinrider/scripts/polinrider_scan.py "$RUNNER_TEMP/polinrider_scan.py"
rm -rf .polinrider
python3 "$RUNNER_TEMP/polinrider_scan.py" --self-test
python3 "$RUNNER_TEMP/polinrider_scan.py" .
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
- run: corepack enable
# Trusted publishing needs npm >= 11.5.1; Node 22 ships npm 10.
- run: npm install -g npm@11.16.0
- run: yarn install --immutable
# main only takes changes through a pull request, so the version bump cannot be
# pushed from here. Pending changesets are versioned on the version-packages
# branch and offered as a "Version packages" PR; merging that PR runs this
# workflow again with nothing pending, and that run publishes.
- name: Version pending changesets
id: version
env:
GH_TOKEN: ${{ github.token }}
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"
run: |
if ! ls .changeset/*.md 2>/dev/null | grep -qv README.md; then
echo "No pending changesets."
exit 0
fi
echo "pending=true" >> "$GITHUB_OUTPUT"
yarn version-packages
git config user.name "github-actions[bot]"
git config user.email "41898283+github-actions[bot]@users.noreply.github.com"
git checkout -B version-packages
git add -A
git commit -m "Version packages"
git push --force origin version-packages
git checkout --quiet "$GITHUB_SHA"
if [ -z "$(gh pr list --head version-packages --state open --json number --jq '.[].number')" ]; then
gh pr create --base main --head version-packages --title "Version packages" \
--body "Pending changesets versioned by the Release workflow. Merging this PR publishes the new versions." \
|| echo "::warning::Could not open the PR. Open it by hand: ${{ github.server_url }}/${{ github.repository }}/compare/main...version-packages"
fi
# A PR opened with GITHUB_TOKEN gets no pull_request runs, but workflow_dispatch
# is exempt, so start the required checks on the branch directly.
gh workflow run polinrider-scan.yml --ref version-packages || true
gh workflow run ci.yml --ref version-packages || true
echo "::notice::Changesets were versioned on the version-packages branch. Merge the Version packages PR to publish."
- if: steps.version.outputs.pending != 'true'
run: yarn build
# Idempotent: publishes only versions not already on the registry, so a rerun after a partial failure is safe.
# One package failing (for example ENEEDAUTH when its npmjs.com trusted publisher is not set up) does not
# stop the others; the step fails at the end and names what did not publish.
- name: Publish
if: steps.version.outputs.pending != 'true'
run: |
failed=""
for dir in helpers apihelper apphelper content-providers integration-sdk texting; do
name=$(node -p "require('./$dir/package.json').name")
version=$(node -p "require('./$dir/package.json').version")
if npm view "$name@$version" version >/dev/null 2>&1; then
echo "$name@$version already published"
elif ! (cd "$dir" && npm publish --provenance --access public --ignore-scripts); then
echo "::error::$name@$version did not publish"
failed="$failed $name@$version"
fi
done
if [ -n "$failed" ]; then
echo "Failed to publish:$failed"
exit 1
fi