Skip to content

Commit f9d1577

Browse files
ci: updated workflows
1 parent 1b7f5f2 commit f9d1577

File tree

7 files changed

+261
-19
lines changed

7 files changed

+261
-19
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Install NPM packages
2+
description: Adds NPM token and install node modules
3+
4+
inputs:
5+
NPM_TOKEN:
6+
description: NPM token
7+
required: false
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Add NPM token to .npmrc
13+
if: inputs.NPM_TOKEN != ''
14+
shell: bash
15+
run: |
16+
if [[ -f .npmrc ]]; then
17+
export NPM_TOKEN=${{ inputs.NPM_TOKEN }}
18+
else
19+
echo "//registry.npmjs.org/:_authToken=${{ inputs.NPM_TOKEN }}" > .npmrc
20+
fi
21+
22+
- name: Install dependencies
23+
shell: bash
24+
run: |
25+
export HUSKY=0
26+
export SKIP_INSTALL_SIMPLE_GIT_HOOKS=1
27+
28+
npm config set audit=false fund=false
29+
30+
npm ci
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Semantic Release
2+
description: Release
3+
4+
inputs:
5+
artifactName:
6+
description: Name of the uploaded build artifact
7+
default: build-artifact
8+
required: false
9+
artifactPath:
10+
description: Destination path for the downloaded build artifact
11+
default: dist
12+
required: false
13+
publishToNpm:
14+
description: Enable this to publish artifacts to NPM
15+
required: false
16+
withoutBuiltArtifact:
17+
description: Indicates that no artifact should be downloaded
18+
required: false
19+
withoutChangelog:
20+
description: Enable this to prevent @semantic-release/changelog from writing a CHANGELOG file
21+
required: false
22+
withoutNpmPlugin:
23+
description: Enable this to prevent @semantic-release/npm from writing package.json
24+
required: false
25+
extraPlugins:
26+
description: Additional array of plugins to be added to the .releaserc file in JSON format
27+
required: false
28+
GITHUB_TOKEN:
29+
description: Github token with write permission
30+
required: true
31+
NPM_TOKEN:
32+
description: Secret NPM token
33+
required: false
34+
35+
outputs:
36+
isReleased:
37+
description: Whether a new release was published. Contains "true" or "false" string
38+
value: ${{ steps.semantic-release.outputs.new_release_published }}
39+
releasedVersion:
40+
description: The version of the release that actually happened
41+
value: ${{ steps.semantic-release.outputs.new_release_version }}
42+
previousVersion:
43+
description: Version of the previous release, if there was one
44+
value: ${{ steps.semantic-release.outputs.last_release_version }}
45+
releasedSHA:
46+
description: The SHA of the commit that was released, that contains the [skip-ci] commit
47+
value: ${{ steps.released-sha.outputs.SHA }}
48+
49+
runs:
50+
using: composite
51+
steps:
52+
- uses: actions/checkout@v4
53+
with:
54+
token: ${{ inputs.GITHUB_TOKEN }}
55+
56+
# install node_modules since there might be a dependency from husky which is invoked during npm publish
57+
- if: inputs.publishToNpm == 'true'
58+
uses: ./.github/actions/npm-install
59+
60+
- if: inputs.withoutBuiltArtifact != 'true'
61+
name: Download artifact
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: ${{ inputs.artifactName }}
65+
path: ${{ inputs.artifactPath }}
66+
67+
- shell: bash
68+
run: |
69+
echo ""
70+
echo "::group::📂 Contents of the Root directory"
71+
ls -la
72+
echo "::endgroup::"
73+
echo ""
74+
75+
- if: inputs.withoutBuiltArtifact != 'true'
76+
shell: bash
77+
run: |
78+
echo ""
79+
echo "::group::📂 Contents of the '${{ inputs.artifactPath }}' directory"
80+
ls -la ${{ inputs.artifactPath }}
81+
echo "::endgroup::"
82+
echo ""
83+
84+
- name: Create config file for Semantic Release
85+
uses: actions/github-script@v7
86+
with:
87+
script: |
88+
const fs = require('fs');
89+
const inputs = ${{ toJSON(inputs) }};
90+
91+
const plugins = [
92+
['@semantic-release/commit-analyzer', {
93+
releaseRules: [
94+
{ type: 'perf', release: 'patch' },
95+
{ type: 'refactor', release: 'patch' },
96+
{ type: 'revert', release: 'patch' }
97+
]
98+
}],
99+
'@semantic-release/release-notes-generator',
100+
];
101+
102+
if (inputs.withoutChangelog !== 'true') {
103+
plugins.push('@semantic-release/changelog');
104+
}
105+
106+
if (inputs.withoutNpmPlugin !== 'true') {
107+
plugins.push([
108+
'@semantic-release/npm',
109+
{ npmPublish: inputs.publishToNpm === 'true' },
110+
]);
111+
}
112+
113+
plugins.push('@semantic-release/github');
114+
plugins.push('@semantic-release/git');
115+
116+
const extraPlugins = JSON.parse(inputs.extraPlugins || '[]');
117+
118+
if (extraPlugins.length) {
119+
extraPlugins.forEach(plugin => plugins.push(plugin));
120+
}
121+
122+
fs.writeFileSync('.releaserc', JSON.stringify({ plugins }, null, 2));
123+
124+
const extraPluginNames = extraPlugins.map(plugin => Array.isArray(plugin) ? plugin[0] : plugin).join(' ');
125+
core.exportVariable('EXTRA_PLUGINS', extraPluginNames);
126+
127+
console.log('::group::📂 Contents of .releaserc:');
128+
console.log(fs.readFileSync('.releaserc'));
129+
console.log('::endgroup::');
130+
131+
- name: Semantic Release
132+
uses: cycjimmy/semantic-release-action@v4
133+
id: semantic-release
134+
with:
135+
branches: |
136+
[
137+
'main',
138+
'+([0-9])?(.{+([0-9]),x}).x'
139+
]
140+
extra_plugins: |
141+
@semantic-release/changelog
142+
@semantic-release/git
143+
${{ env.EXTRA_PLUGINS }}
144+
env:
145+
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
146+
NPM_TOKEN: ${{ inputs.NPM_TOKEN }}
147+
HUSKY: '0'
148+
149+
- name: Output commit hash
150+
id: released-sha
151+
shell: bash
152+
run: |
153+
echo ""
154+
if [[ "${{ steps.semantic-release.outputs.new_release_published }}" == true ]]; then
155+
echo "::notice::🎉 Application version was updated to ${{ steps.semantic-release.outputs.new_release_version }}"
156+
else
157+
echo "::warning::No new version is released"
158+
echo "::warning::Make sure that commit messages follow the semantic-release format"
159+
fi
160+
echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Lint, Test and Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
shouldUploadArtifact:
7+
required: false
8+
type: string
9+
10+
jobs:
11+
lint-test-build:
12+
name: Lint, Test, Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: ./.github/actions/npm-install
17+
with:
18+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
19+
20+
- name: Lint
21+
run: npm run lint && npm run lint:ts
22+
23+
- name: Test
24+
run: npm run test:coverage
25+
26+
- name: Build
27+
run: npm run build
28+
29+
- name: Upload artifact
30+
if: inputs.shouldUploadArtifact == 'true'
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: build-artifact
34+
path: dist
35+
if-no-files-found: error

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generic workflow to lint, test, build and publish an npm package
2+
3+
name: Test, Build and Publish npm package
4+
5+
on:
6+
push:
7+
branches: main
8+
9+
jobs:
10+
lint-test-build:
11+
name: Validate
12+
uses: ./.github/workflows/on-call-lint-test-build.yml
13+
secrets: inherit
14+
with:
15+
shouldUploadArtifact: true
16+
17+
release:
18+
name: Publish to NPM 🚀
19+
runs-on: ubuntu-latest
20+
needs: lint-test-build
21+
permissions:
22+
id-token: write
23+
contents: write
24+
steps:
25+
- name: Semantic Release
26+
uses: cloudbeds/webpack-module-federation-types-plugin/.github/actions/semantic-release@main
27+
with:
28+
publishToNpm: true
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/push.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Push to branch
1+
name: Lint, Test and Build
22

33
on:
44
push:
5-
branches-ignore:
6-
- main
5+
branches-ignore: main
76

87
jobs:
9-
push:
10-
uses: cloudbeds/workflows/.github/workflows/npm-build-test.yml@main
8+
lint-test-build:
9+
name: Validate
10+
uses: ./.github/workflows/on-call-lint-test-build.yml
1111
secrets: inherit

.github/workflows/release.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"scripts": {
2020
"build": "tsc",
2121
"watch": "tsc -w",
22+
"check": "npm run lint && npm run lint:ts && npm test",
2223
"lint": "biome check --write --unsafe",
2324
"lint:ts": "tsc --noEmit",
2425
"prepare": "simple-git-hooks",

0 commit comments

Comments
 (0)