@defra/forms-engine-plugin 0.0.3 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +192 -19
- package/package.json +1 -1
|
@@ -1,32 +1,127 @@
|
|
|
1
|
-
name: Publish Engine
|
|
1
|
+
name: Publish Engine Plugin
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
-
workflow_dispatch:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
version_bump:
|
|
7
|
+
description: 'Type of version bump to perform'
|
|
8
|
+
required: true
|
|
9
|
+
default: 'patch'
|
|
10
|
+
type: choice
|
|
11
|
+
options:
|
|
12
|
+
- patch
|
|
13
|
+
- minor
|
|
14
|
+
- major
|
|
15
|
+
npm_tag:
|
|
16
|
+
description: 'Custom npm dist-tag (ALWAYS specify for non-standard branches to avoid overwriting latest)'
|
|
17
|
+
required: false
|
|
18
|
+
default: 'dev'
|
|
19
|
+
type: string
|
|
20
|
+
dry_run:
|
|
21
|
+
description: 'Dry run (no actual publishing)'
|
|
22
|
+
required: false
|
|
23
|
+
default: true
|
|
24
|
+
type: boolean
|
|
5
25
|
|
|
6
26
|
push:
|
|
7
27
|
branches:
|
|
8
28
|
- main
|
|
9
|
-
|
|
10
|
-
- '.browserslistrc'
|
|
11
|
-
- 'babel.config.*'
|
|
12
|
-
- 'src/**'
|
|
13
|
-
- '!**/*.test.*'
|
|
29
|
+
- 'release/v[0-9]*'
|
|
14
30
|
|
|
15
31
|
concurrency:
|
|
16
|
-
group: publish-engine-plugin
|
|
32
|
+
group: publish-engine-plugin-${{ github.ref }}
|
|
17
33
|
|
|
18
34
|
permissions:
|
|
19
35
|
contents: write
|
|
20
36
|
packages: write
|
|
21
37
|
|
|
22
38
|
jobs:
|
|
39
|
+
determine-path:
|
|
40
|
+
name: Determine Workflow Path
|
|
41
|
+
runs-on: ubuntu-24.04
|
|
42
|
+
outputs:
|
|
43
|
+
workflow-path: ${{ steps.check-path.outputs.workflow-path }}
|
|
44
|
+
version-bump: ${{ steps.check-path.outputs.version-bump }}
|
|
45
|
+
npm-tag: ${{ steps.check-path.outputs.npm-tag }}
|
|
46
|
+
|
|
47
|
+
steps:
|
|
48
|
+
- name: Check out code
|
|
49
|
+
uses: actions/checkout@v4
|
|
50
|
+
with:
|
|
51
|
+
fetch-depth: 2
|
|
52
|
+
|
|
53
|
+
- name: Determine workflow path
|
|
54
|
+
id: check-path
|
|
55
|
+
run: |
|
|
56
|
+
# Default values
|
|
57
|
+
WORKFLOW_PATH="unknown"
|
|
58
|
+
SHOULD_BUILD="false"
|
|
59
|
+
VERSION_BUMP="patch"
|
|
60
|
+
NPM_TAG=""
|
|
61
|
+
|
|
62
|
+
# Manual workflow dispatch
|
|
63
|
+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
|
64
|
+
echo "🔵 Manual workflow trigger detected"
|
|
65
|
+
WORKFLOW_PATH="manual"
|
|
66
|
+
SHOULD_BUILD="true"
|
|
67
|
+
VERSION_BUMP="${{ github.event.inputs.version_bump }}"
|
|
68
|
+
NPM_TAG="${{ github.event.inputs.npm_tag }}"
|
|
69
|
+
|
|
70
|
+
# Automatic triggers from push events
|
|
71
|
+
elif [[ "${{ github.event_name }}" == "push" ]]; then
|
|
72
|
+
# Check for version bump commit first
|
|
73
|
+
COMMIT_MSG=$(git log -1 --pretty=%B)
|
|
74
|
+
if [[ "$COMMIT_MSG" == *"MINOR"* || "$COMMIT_MSG" == *"MAJOR"* ]]; then
|
|
75
|
+
echo "🟢 Version bump commit detected!"
|
|
76
|
+
WORKFLOW_PATH="version-bump"
|
|
77
|
+
SHOULD_BUILD="true"
|
|
78
|
+
|
|
79
|
+
if [[ "$COMMIT_MSG" == *"MINOR"* ]]; then
|
|
80
|
+
echo "Minor version bump"
|
|
81
|
+
VERSION_BUMP="minor"
|
|
82
|
+
elif [[ "$COMMIT_MSG" == *"MAJOR"* ]]; then
|
|
83
|
+
echo "Major version bump"
|
|
84
|
+
VERSION_BUMP="major"
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
# Next, check if any relevant files changed (matching the original path filters)
|
|
88
|
+
elif git diff --name-only HEAD^ HEAD | grep -v "\.test\." | grep -q -E "(^\.browserslistrc$|^babel\.config\.|^src/)"; then
|
|
89
|
+
echo "🟠 Relevant file changes detected"
|
|
90
|
+
WORKFLOW_PATH="file-changes"
|
|
91
|
+
SHOULD_BUILD="true"
|
|
92
|
+
|
|
93
|
+
# No relevant changes - skip publishing
|
|
94
|
+
else
|
|
95
|
+
echo "⚪ No publishing-relevant changes detected"
|
|
96
|
+
WORKFLOW_PATH="skip"
|
|
97
|
+
fi
|
|
98
|
+
fi
|
|
99
|
+
|
|
100
|
+
# Set outputs for downstream jobs
|
|
101
|
+
echo "workflow-path=$WORKFLOW_PATH" >> $GITHUB_OUTPUT
|
|
102
|
+
echo "should-build=$SHOULD_BUILD" >> $GITHUB_OUTPUT
|
|
103
|
+
echo "version-bump=$VERSION_BUMP" >> $GITHUB_OUTPUT
|
|
104
|
+
echo "npm-tag=$NPM_TAG" >> $GITHUB_OUTPUT
|
|
105
|
+
|
|
106
|
+
# Summary for logs
|
|
107
|
+
echo "==========================================="
|
|
108
|
+
echo "Workflow Path: $WORKFLOW_PATH"
|
|
109
|
+
echo "Should Build: $SHOULD_BUILD"
|
|
110
|
+
echo "Version Bump: $VERSION_BUMP"
|
|
111
|
+
echo "NPM Tag: ${NPM_TAG:-<auto-detect>}"
|
|
112
|
+
echo "==========================================="
|
|
113
|
+
|
|
23
114
|
build:
|
|
24
115
|
name: Build
|
|
116
|
+
needs: [determine-path]
|
|
117
|
+
if: needs.determine-path.outputs.workflow-path != 'skip'
|
|
25
118
|
runs-on: ubuntu-24.04
|
|
26
119
|
|
|
27
120
|
steps:
|
|
28
121
|
- name: Check out code
|
|
29
122
|
uses: actions/checkout@v4
|
|
123
|
+
with:
|
|
124
|
+
fetch-depth: 0
|
|
30
125
|
|
|
31
126
|
- name: Cache dependencies
|
|
32
127
|
uses: actions/cache@v4
|
|
@@ -60,30 +155,35 @@ jobs:
|
|
|
60
155
|
|
|
61
156
|
publish:
|
|
62
157
|
name: Publish
|
|
158
|
+
needs: [determine-path, build]
|
|
159
|
+
if: needs.determine-path.outputs.workflow-path != 'skip'
|
|
63
160
|
runs-on: ubuntu-24.04
|
|
64
|
-
needs: [build]
|
|
65
161
|
environment: production
|
|
66
162
|
|
|
67
163
|
steps:
|
|
68
164
|
- name: Check out code
|
|
69
165
|
uses: actions/checkout@v4
|
|
70
166
|
with:
|
|
71
|
-
fetch-depth:
|
|
72
|
-
ref:
|
|
167
|
+
fetch-depth: 2
|
|
168
|
+
ref: ${{ github.ref }}
|
|
169
|
+
|
|
170
|
+
- name: Display workflow path
|
|
171
|
+
run: |
|
|
172
|
+
echo "⭐ Executing ${{ needs.determine-path.outputs.workflow-path }} workflow path"
|
|
173
|
+
echo "Version bump type: ${{ needs.determine-path.outputs.version-bump }}"
|
|
174
|
+
echo "NPM Tag: ${{ needs.determine-path.outputs.npm-tag || '<auto-detect>' }}"
|
|
73
175
|
|
|
74
176
|
- name: Restore dependencies
|
|
75
177
|
uses: actions/cache/restore@v4
|
|
76
178
|
with:
|
|
77
179
|
enableCrossOsArchive: true
|
|
78
|
-
fail-on-cache-miss: true
|
|
79
180
|
key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
|
|
80
181
|
path: node_modules
|
|
81
182
|
|
|
82
|
-
- name: Restore build
|
|
183
|
+
- name: Restore build artifacts
|
|
83
184
|
uses: actions/cache/restore@v4
|
|
84
185
|
with:
|
|
85
186
|
enableCrossOsArchive: true
|
|
86
|
-
fail-on-cache-miss: true
|
|
87
187
|
key: npm-build-${{ runner.os }}-${{ github.sha }}
|
|
88
188
|
path: |
|
|
89
189
|
.server
|
|
@@ -96,16 +196,89 @@ jobs:
|
|
|
96
196
|
registry-url: https://registry.npmjs.org
|
|
97
197
|
scope: '@defra'
|
|
98
198
|
|
|
99
|
-
- name:
|
|
100
|
-
|
|
199
|
+
- name: Determine version bump details
|
|
200
|
+
id: version-details
|
|
201
|
+
run: |
|
|
202
|
+
BRANCH_NAME="${{ github.ref_name }}"
|
|
203
|
+
VERSION_TYPE="${{ needs.determine-path.outputs.version-bump }}"
|
|
204
|
+
|
|
205
|
+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
|
|
206
|
+
|
|
207
|
+
# Check for invalid version bumps on release branches
|
|
208
|
+
if [[ "$BRANCH_NAME" =~ release/v([0-9]+) ]]; then
|
|
209
|
+
MAJOR_VERSION="${BASH_REMATCH[1]}"
|
|
210
|
+
|
|
211
|
+
# Fail if a major bump was requested on a release branch
|
|
212
|
+
if [[ "$VERSION_TYPE" == "major" ]]; then
|
|
213
|
+
echo "::error::⛔ MAJOR VERSION BUMP NOT ALLOWED ON RELEASE BRANCH"
|
|
214
|
+
echo "::error::Branch release/v${MAJOR_VERSION} is locked to major version ${MAJOR_VERSION}."
|
|
215
|
+
echo "::error::To publish a new major version, create a new branch named release/v$((MAJOR_VERSION+1))."
|
|
216
|
+
exit 1
|
|
217
|
+
fi
|
|
218
|
+
|
|
219
|
+
# Set the package version to match the major version if needed
|
|
220
|
+
CURRENT_VERSION=$(npm pkg get version | tr -d \")
|
|
221
|
+
CURRENT_MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
|
|
222
|
+
|
|
223
|
+
# If the major version doesn't match, reset to major.0.0
|
|
224
|
+
if [[ "$CURRENT_MAJOR" != "$MAJOR_VERSION" ]]; then
|
|
225
|
+
npm version $MAJOR_VERSION.0.0 --git-tag-version false --allow-same-version
|
|
226
|
+
|
|
227
|
+
# Override to patch since we've already set the version
|
|
228
|
+
VERSION_TYPE="patch"
|
|
229
|
+
fi
|
|
230
|
+
fi
|
|
231
|
+
|
|
232
|
+
echo "VERSION_TYPE=$VERSION_TYPE" >> $GITHUB_ENV
|
|
233
|
+
|
|
234
|
+
- name: Update package version
|
|
235
|
+
run: |
|
|
236
|
+
echo "Bumping version: $VERSION_TYPE"
|
|
237
|
+
npm version $VERSION_TYPE --git-tag-version false --save
|
|
101
238
|
|
|
102
239
|
- name: Commit and push updates
|
|
103
240
|
run: |
|
|
104
241
|
git config user.name github-actions
|
|
105
242
|
git config user.email github-actions@github.com
|
|
106
|
-
|
|
243
|
+
NEW_VERSION=$(npm pkg get version | tr -d \")
|
|
244
|
+
git commit -am "v$NEW_VERSION [skip ci]" && git push
|
|
107
245
|
|
|
108
|
-
- name: Publish to npm
|
|
109
|
-
run:
|
|
246
|
+
- name: Publish to npm with appropriate dist-tag
|
|
247
|
+
run: |
|
|
248
|
+
BRANCH_NAME="${BRANCH_NAME}"
|
|
249
|
+
NEW_VERSION=$(npm pkg get version | tr -d \")
|
|
250
|
+
PUBLISH_ARGS="--access public"
|
|
251
|
+
|
|
252
|
+
# First priority: Check for custom tag from inputs
|
|
253
|
+
if [[ -n "${{ needs.determine-path.outputs.npm-tag }}" ]]; then
|
|
254
|
+
DIST_TAG="${{ needs.determine-path.outputs.npm-tag }}"
|
|
255
|
+
PUBLISH_ARGS="$PUBLISH_ARGS --tag $DIST_TAG"
|
|
256
|
+
echo "Publishing v$NEW_VERSION with custom tag '$DIST_TAG'"
|
|
257
|
+
# Second priority: Check for branch-specific tags
|
|
258
|
+
elif [[ "$BRANCH_NAME" == "main" ]]; then
|
|
259
|
+
echo "Publishing v$NEW_VERSION from main -> using default 'latest' tag"
|
|
260
|
+
elif [[ "$BRANCH_NAME" =~ release/v([0-9]+) ]]; then
|
|
261
|
+
MAJOR_VERSION="${BASH_REMATCH[1]}"
|
|
262
|
+
# Using Mongoose-style tag format: 1x, 2x, 3x
|
|
263
|
+
DIST_TAG="${MAJOR_VERSION}x"
|
|
264
|
+
PUBLISH_ARGS="$PUBLISH_ARGS --tag $DIST_TAG"
|
|
265
|
+
echo "Publishing v$NEW_VERSION from $BRANCH_NAME -> using tag '$DIST_TAG'"
|
|
266
|
+
else
|
|
267
|
+
# Safety check for non-standard branches
|
|
268
|
+
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -z "${{ needs.determine-path.outputs.npm-tag }}" ]]; then
|
|
269
|
+
echo "⚠️ WARNING: Publishing from non-standard branch '$BRANCH_NAME' without a custom npm tag"
|
|
270
|
+
echo "⚠️ This will publish as 'latest' and may overwrite your production release"
|
|
271
|
+
fi
|
|
272
|
+
echo "Branch $BRANCH_NAME doesn't match expected patterns, using default publishing"
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
# Add dry-run flag if specified (for manual workflow)
|
|
276
|
+
if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then
|
|
277
|
+
PUBLISH_ARGS="$PUBLISH_ARGS --dry-run"
|
|
278
|
+
echo "DRY RUN MODE - No actual publishing will occur"
|
|
279
|
+
fi
|
|
280
|
+
|
|
281
|
+
# Execute npm publish with all arguments
|
|
282
|
+
npm publish $PUBLISH_ARGS
|
|
110
283
|
env:
|
|
111
284
|
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
|