|
1 | | -name: Publish Engine Plugin |
2 | | - |
| 1 | +name: Publish to NPM |
3 | 2 | on: |
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 tag (only needed for non-standard branches; release branches will use their major version tag automatically)' |
17 | | - required: false |
18 | | - default: 'beta' |
19 | | - type: string |
20 | | - dry_run: |
21 | | - description: 'Dry run (no actual publishing)' |
22 | | - required: false |
23 | | - default: true |
24 | | - type: boolean |
25 | | - |
26 | | - push: |
27 | | - branches: |
28 | | - - main |
29 | | - - 'release/v[0-9]*' |
30 | | - |
31 | | -concurrency: |
32 | | - group: publish-engine-plugin-${{ github.ref }} |
33 | | - |
34 | | -permissions: |
35 | | - contents: write |
36 | | - packages: write |
37 | | - |
| 3 | + release: |
| 4 | + types: |
| 5 | + - published |
38 | 6 | 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: bash .github/scripts/publish/determine-workflow-path.sh "${{ github.event_name }}" "${{ github.event.inputs.version_bump }}" "${{ github.event.inputs.npm_tag }}" |
56 | | - |
57 | | - build: |
58 | | - name: Build |
59 | | - needs: [determine-path] |
60 | | - if: needs.determine-path.outputs.workflow-path != 'skip' |
61 | | - runs-on: ubuntu-24.04 |
| 7 | + ci: |
| 8 | + uses: ./.github/workflows/check-pull-request.yml |
| 9 | + secrets: inherit |
| 10 | + with: |
| 11 | + skip-sonar: true |
62 | 12 |
|
| 13 | + publish: |
| 14 | + needs: ci |
| 15 | + runs-on: ubuntu-latest |
63 | 16 | steps: |
64 | | - - name: Check out code |
65 | | - uses: actions/checkout@v4 |
| 17 | + - uses: actions/checkout@v4 |
66 | 18 | with: |
67 | 19 | fetch-depth: 0 |
| 20 | + ref: ${{ github.event.release.tag_name }} |
68 | 21 |
|
69 | | - - name: Cache dependencies |
70 | | - uses: actions/cache@v4 |
71 | | - id: npm-install-cache |
| 22 | + - uses: actions/setup-node@v5 |
72 | 23 | with: |
73 | | - enableCrossOsArchive: true |
74 | | - key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }} |
75 | | - path: node_modules |
| 24 | + node-version-file: .nvmrc |
| 25 | + registry-url: 'https://registry.npmjs.org' |
| 26 | + cache: 'npm' |
76 | 27 |
|
77 | | - - name: Cache build |
| 28 | + - name: Cache webpack and build artifacts |
78 | 29 | uses: actions/cache@v4 |
79 | 30 | with: |
80 | | - enableCrossOsArchive: true |
81 | | - key: npm-build-${{ runner.os }}-${{ github.sha }} |
82 | 31 | path: | |
83 | | - .server |
84 | | - .public |
85 | | -
|
86 | | - - name: Setup Node.js |
87 | | - uses: actions/setup-node@v4 |
88 | | - with: |
89 | | - cache: 'npm' |
90 | | - node-version-file: .nvmrc |
| 32 | + node_modules/.cache/webpack |
| 33 | + node_modules/.cache/terser-webpack-plugin |
| 34 | + key: ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('webpack.*.mjs', 'babel.config.json') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}- |
| 37 | + ${{ runner.os }}-build- |
91 | 38 |
|
92 | 39 | - name: Install dependencies |
93 | | - if: steps.npm-install-cache.outputs.cache-hit != 'true' |
94 | 40 | run: npm ci |
95 | 41 |
|
96 | | - - name: Run build |
| 42 | + - name: Build |
97 | 43 | run: npm run build |
98 | 44 |
|
99 | | - publish: |
100 | | - name: Publish |
101 | | - needs: [determine-path, build] |
102 | | - if: needs.determine-path.outputs.workflow-path != 'skip' |
103 | | - runs-on: ubuntu-24.04 |
104 | | - environment: production |
105 | | - |
106 | | - steps: |
107 | | - - name: Check out code |
108 | | - uses: actions/checkout@v4 |
109 | | - with: |
110 | | - fetch-depth: 2 |
111 | | - ref: ${{ github.ref }} |
112 | | - |
113 | | - - name: Display workflow path |
114 | | - run: | |
115 | | - echo "⭐ Executing ${{ needs.determine-path.outputs.workflow-path }} workflow path" |
116 | | - echo "Version bump type: ${{ needs.determine-path.outputs.version-bump }}" |
117 | | - echo "NPM Tag: ${{ needs.determine-path.outputs.npm-tag || '<auto-detect>' }}" |
118 | | -
|
119 | | - - name: Restore dependencies |
120 | | - uses: actions/cache/restore@v4 |
121 | | - with: |
122 | | - enableCrossOsArchive: true |
123 | | - key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }} |
124 | | - path: node_modules |
125 | | - |
126 | | - - name: Restore build artifacts |
127 | | - uses: actions/cache/restore@v4 |
128 | | - with: |
129 | | - enableCrossOsArchive: true |
130 | | - key: npm-build-${{ runner.os }}-${{ github.sha }} |
131 | | - path: | |
132 | | - .server |
133 | | - .public |
134 | | -
|
135 | | - - name: Setup Node.js |
136 | | - uses: actions/setup-node@v4 |
137 | | - with: |
138 | | - node-version-file: .nvmrc |
139 | | - registry-url: https://registry.npmjs.org |
140 | | - scope: '@defra' |
141 | | - |
142 | | - - name: Determine version bump details |
143 | | - id: version-details |
144 | | - run: bash .github/scripts/publish/version-bump-details.sh "${{ github.ref_name }}" "${{ needs.determine-path.outputs.version-bump }}" |
145 | | - |
146 | | - - name: Update package version |
147 | | - run: | |
148 | | - echo "Bumping version: $VERSION_TYPE" |
149 | | - npm version $VERSION_TYPE --git-tag-version false --save |
150 | | -
|
151 | | - - name: Commit and push updates |
152 | | - run: | |
153 | | - git config user.name github-actions |
154 | | - git config user.email github-actions@github.com |
155 | | - NEW_VERSION=$(npm pkg get version | tr -d \") |
156 | | - git commit -am "v$NEW_VERSION [skip ci]" && git push |
157 | | -
|
158 | | - - name: Publish to npm with appropriate dist-tag |
159 | | - run: bash .github/scripts/publish/publish-to-npm.sh "${{ github.ref_name }}" "${{ needs.determine-path.outputs.workflow-path }}" "${{ needs.determine-path.outputs.npm-tag }}" "${{ github.event.inputs.dry_run }}" |
| 45 | + - name: Publish |
| 46 | + run: ./scripts/publish-package.sh "${{ github.event.release.tag_name }}" "${{ github.event.release.prerelease }}" |
160 | 47 | env: |
161 | | - NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} |
162 | | - |
163 | | - generate-docs: |
164 | | - name: Generate and Publish Documentation |
165 | | - needs: [publish] |
166 | | - if: needs.determine-path.outputs.workflow-path != 'skip' && (startsWith(github.ref, 'refs/heads/release/v') || github.ref == 'refs/heads/main') |
167 | | - runs-on: ubuntu-24.04 |
168 | | - permissions: |
169 | | - contents: read |
170 | | - pages: write |
171 | | - id-token: write |
172 | | - |
173 | | - steps: |
174 | | - - name: Check out code |
175 | | - uses: actions/checkout@v4 |
176 | | - |
177 | | - - name: Restore dependencies |
178 | | - uses: actions/cache/restore@v4 |
179 | | - with: |
180 | | - enableCrossOsArchive: true |
181 | | - key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }} |
182 | | - path: node_modules |
183 | | - |
184 | | - - name: Setup Node.js |
185 | | - uses: actions/setup-node@v4 |
186 | | - with: |
187 | | - node-version-file: .nvmrc |
188 | | - |
189 | | - - name: Generate and process documentation |
190 | | - run: bash .github/scripts/docs/generate-and-publish-docs.sh "${{ github.ref_name }}" "$(npm pkg get version | tr -d \")" |
191 | | - |
192 | | - - name: Setup Pages |
193 | | - uses: actions/configure-pages@v5 |
194 | | - |
195 | | - - name: Upload artifact |
196 | | - uses: actions/upload-pages-artifact@v3 |
197 | | - with: |
198 | | - path: './docs-site' |
199 | | - |
200 | | - - name: Deploy to GitHub Pages |
201 | | - id: deployment |
202 | | - uses: actions/deploy-pages@v4 |
| 48 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments