-
Notifications
You must be signed in to change notification settings - Fork 33
141 lines (119 loc) · 4.4 KB
/
ci.yaml
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
name: Continuous Integration
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- master
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_BRANCH: ${{ github.head_ref }}
BASE: ${{ github.base_ref || github.event.repository.default_branch}}
jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Nx set sha
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: ${{ env.BASE }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: "package.json"
cache: "npm"
cache-dependency-path: "package-lock.json"
- name: Install dependencies
run: npm ci
- name: Get changed files
id: files
uses: tj-actions/changed-files@v42
with:
files_ignore: package-lock.json
base_sha: ${{ steps.setSHAs.outputs.base }}
separator: ","
- name: Lint
run: npx nx affected --target=lint --parallel --files=${{ steps.files.outputs.all_changed_files }}
- name: Build
run: npx nx affected --target=build --parallel --files=${{ steps.files.outputs.all_changed_files }}
- name: Test
run: npx nx affected --target=test --parallel --files=${{ steps.files.outputs.all_changed_files }}
nx:
name: Nx
needs: ci
uses: ./.github/workflows/nx.template.yaml
with:
nx-head: ${{ github.head_ref && format('refs/pull/{0}/merge', github.event.number) || github.ref_name }}
nx-base: ${{ github.base_ref || inputs.nx-base || github.event.repository.default_branch }}
plugin-version-validator:
runs-on: ubuntu-latest
name: Plugin Version Validator
needs: nx
if: ${{ github.event_name == 'pull_request' && needs.nx.outputs.affected-plugins != '[]' && needs.nx.outputs.affected-plugins != '' }}
strategy:
fail-fast: false
matrix:
affected-plugin: ${{ fromJson(needs.nx.outputs.affected-plugins) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get plugin version from PR
id: get-plugin-version
run: |
PLUGIN_PATH="plugins/${{ matrix.affected-plugin }}/package.json"
echo "version=$(cat $PLUGIN_PATH | jq -r '.version')" >> $GITHUB_OUTPUT
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
- name: Get current latest plugin version from the base branch
id: get-current-latest-version
run: |
PLUGIN_PATH="plugins/${{ matrix.affected-plugin }}/package.json"
echo "version=$(cat $PLUGIN_PATH | jq -r '.version')" >> $GITHUB_OUTPUT
- name: Check if versions are equal
id: check-version
run: |
if [ "${{ steps.get-plugin-version.outputs.version }}" == "${{ steps.get-current-latest-version.outputs.version }}" ]; then
echo "❌ Versions are equal. Please bump the version in ${{ matrix.affected-plugin }} 😵"
exit 1
else
echo "✅ Versions are not equal. All good"
exit 0
fi
publish:
name: Publish latest version
runs-on: ubuntu-latest
needs: nx
if: ${{ github.event_name == 'push' && needs.nx.outputs.affected-plugins != '[]' && needs.nx.outputs.affected-plugins != '' }}
strategy:
matrix:
affected-plugin: ${{ fromJson(needs.nx.outputs.affected-plugins) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies and build 🔧
run: npm ci
- name: Build
run: npx nx build ${{ matrix.affected-plugin }}
- name: Publish version dry-run
run: npm publish --access public --dry-run
working-directory: plugins/${{ matrix.affected-plugin }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish package on NPM [latest] 📦
run: npm publish --access public
working-directory: plugins/${{ matrix.affected-plugin }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}