-
Notifications
You must be signed in to change notification settings - Fork 3.9k
157 lines (143 loc) · 5.49 KB
/
Copy pathpublish.yml
File metadata and controls
157 lines (143 loc) · 5.49 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Publish to npm
on:
workflow_dispatch:
inputs:
dry_run:
description: >
Dry run — print the version and npm dist-tag that would be used; no commit or publish.
Pick the branch to publish from with the "Use workflow from" dropdown.
Non-default branches publish to the npm dist-tag `beta` (not `latest`).
required: false
default: false
type: boolean
skip_versioning:
description: >
Skip version bump — use the version already in the repo
(e.g. retry after npm publish failed but the release commit is already pushed).
required: false
default: false
type: boolean
version_override:
description: >
Optional. Full semver to publish (e.g. 12.6.0-beta.2). Skips conventional bump when set.
Leave empty for automatic versioning.
required: false
default: ''
type: string
permissions:
contents: write
id-token: write
jobs:
ci:
uses: ./.github/workflows/build.yml
publish:
needs: ci
runs-on: ubuntu-latest
# Don't try to publish from a fork of RaspberryPiFoundation/blockly.
if: ${{ github.repository_owner == 'RaspberryPiFoundation' }}
environment: release
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.ref }}
fetch-depth: 0
ssh-key: ${{ secrets.DEPLOY_PRIVATE_KEY }}
# This uses a reverse-engineered email for the github actions bot. See
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
- name: Git Identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '<41898282+github-actions[bot]@users.noreply.github.com'
- name: Setup Node.js
uses: actions/setup-node@v7
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Determine Dist Tag
id: dist
env:
VERSION_OVERRIDE: ${{ inputs.version_override }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
REF_NAME: ${{ github.ref_name }}
run: |
DIST_TAG=$([[ "${VERSION_OVERRIDE}" == *"-beta."* || "${REF_NAME}" != "${DEFAULT_BRANCH}" ]] && echo "beta" || echo "latest")
echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
echo "NPM distribution tag: $DIST_TAG"
- name: Version
if: ${{ !inputs.skip_versioning }}
env:
GH_TOKEN: ${{ github.token }}
VERSION_OVERRIDE: ${{ inputs.version_override }}
DRY_RUN: ${{ inputs.dry_run }}
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
run: |
set -euo pipefail
VERSION_COMMAND="npx lerna version"
if [ -n "${VERSION_OVERRIDE}" ]; then
VERSION_COMMAND="${VERSION_COMMAND} ${VERSION_OVERRIDE}"
fi
if [ "${DIST_TAG}" = "latest" ]; then
VERSION=$(node -p "require('./packages/blockly/package.json').version")
if [[ "${VERSION}" == *"-beta."* ]]; then
VERSION_COMMAND="${VERSION_COMMAND} --conventional-graduate"
fi
else
VERSION_COMMAND="${VERSION_COMMAND} --conventional-prerelease --preid beta"
fi
VERSION_COMMAND="${VERSION_COMMAND} --force-publish --conventional-commits --yes"
if [ "${DRY_RUN}" = "true" ]; then
VERSION_COMMAND="${VERSION_COMMAND} --no-push --no-git-tag-version"
echo "Dry run: would publish the following versions to npm dist-tag: ${DIST_TAG}"
eval "$VERSION_COMMAND"
if [ "${DIST_TAG}" = "beta" ]; then
echo "GitHub release would be created as prerelease."
fi
else
eval "$VERSION_COMMAND"
fi
- name: Build core package
if: ${{ !inputs.dry_run }}
working-directory: packages/blockly
run: npm run package
- name: Publish
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
SKIP_VERSIONING: ${{ inputs.skip_versioning }}
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
run: |
if [ "${SKIP_VERSIONING}" = "true" ]; then
npx lerna publish from-package --yes --dist-tag ${DIST_TAG} --loglevel silly
else
npx lerna publish from-git --yes --dist-tag ${DIST_TAG} --loglevel silly
fi
- name: Create tarball
if: ${{ !inputs.dry_run }}
working-directory: packages/blockly
run: npm pack ./dist
- name: Create GitHub release
if: ${{ !inputs.dry_run }}
working-directory: packages/blockly
env:
GH_TOKEN: ${{ github.token }}
DIST_TAG: ${{ steps.dist.outputs.dist_tag }}
run: |
VERSION=$(node -p "require('./package.json').version")
TARBALL="blockly-${VERSION}.tgz"
if [ "${DIST_TAG}" == "beta" ]; then
gh release create "blockly-v${VERSION}" "$TARBALL" \
--repo "$GITHUB_REPOSITORY" \
--title "blockly-v${VERSION}" \
--generate-notes \
--prerelease
else
gh release create "blockly-v${VERSION}" "$TARBALL" \
--repo "$GITHUB_REPOSITORY" \
--title "blockly-v${VERSION}" \
--generate-notes
fi