@@ -2,6 +2,7 @@ name: Build
22permissions :
33 contents : read
44 packages : read
5+ actions : write
56
67on :
78 pull_request :
@@ -14,18 +15,55 @@ concurrency:
1415 cancel-in-progress : true
1516
1617jobs :
17- lint :
18+ setup-dependencies :
1819 runs-on : ubuntu-latest
1920 steps :
2021 - uses : actions/checkout@v4
22+
2123 - uses : actions/setup-node@v4
2224 with :
2325 node-version : 20
24- cache : ' npm'
26+
27+ - name : Cache npm dependencies
28+ uses : actions/cache@v4
29+ with :
30+ path : |
31+ ~/.npm
32+ node_modules
33+ key : npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
34+ restore-keys : |
35+ npm-${{ runner.os }}-
2536
2637 - name : Install dependencies
27- run : |
28- npm ci --no-audit
38+ run : npm ci
39+
40+ - name : Compress node_modules
41+ run : tar -czf node_modules.tar.gz node_modules
42+
43+ - name : Upload node_modules for reuse
44+ uses : actions/upload-artifact@v4
45+ with :
46+ name : node-modules
47+ path : node_modules.tar.gz
48+ retention-days : 1
49+
50+ lint :
51+ needs : [setup-dependencies]
52+ runs-on : ubuntu-latest
53+ steps :
54+ - uses : actions/checkout@v4
55+
56+ - uses : actions/setup-node@v4
57+ with :
58+ node-version : 20
59+
60+ - name : Download node_modules
61+ uses : actions/download-artifact@v4
62+ with :
63+ name : node-modules
64+
65+ - name : Extract node_modules
66+ run : tar -xzf node_modules.tar.gz
2967
3068 - name : Run vulnerability audit
3169 # "There is no Vulnerability in Media Viewer after 48.5.4. since it was fixed by patching, but npm audit still reports it.",
@@ -35,22 +73,66 @@ jobs:
3573 - name : Run linter
3674 run : npm run lint
3775
38- ci-matrix :
39- needs : [lint]
76+ test-unit :
77+ needs : [setup-dependencies]
78+ runs-on : ubuntu-latest
79+ steps :
80+ - uses : actions/checkout@v4
81+
82+ - uses : actions/setup-node@v4
83+ with :
84+ node-version : 20
85+
86+ - name : Download node_modules
87+ uses : actions/download-artifact@v4
88+ with :
89+ name : node-modules
90+
91+ - name : Extract node_modules
92+ run : tar -xzf node_modules.tar.gz
93+
94+ - name : Run unit tests
95+ run : npm test
96+
97+ build-extension :
98+ needs : [setup-dependencies]
99+ runs-on : ubuntu-latest
100+ steps :
101+ - uses : actions/checkout@v4
102+
103+ - uses : actions/setup-node@v4
104+ with :
105+ node-version : 20
106+
107+ - name : Download node_modules
108+ uses : actions/download-artifact@v4
109+ with :
110+ name : node-modules
111+
112+ - name : Extract node_modules
113+ run : tar -xzf node_modules.tar.gz
114+
115+ - name : Package the extension
116+ run : npm run extension:package
117+
118+ - name : Upload extension package
119+ uses : actions/upload-artifact@v4
120+ with :
121+ name : extension-package
122+ path : atlascode-*.vsix
123+ retention-days : 1
124+
125+ test-e2e :
126+ needs : [build-extension]
40127 runs-on : ubuntu-latest
41128 strategy :
42- fail-fast : true
129+ fail-fast : false
43130 matrix :
44- include :
45- - kind : unit
46- - kind : e2e
47- target : jira-cloud
48- - kind : e2e
49- target : jira-dc
50- - kind : e2e
51- target : bitbucket-cloud
52- - kind : e2e
53- target : bitbucket-dc
131+ target :
132+ - jira-cloud
133+ - jira-dc
134+ - bitbucket-cloud
135+ - bitbucket-dc
54136
55137 env :
56138 ATLASCODE_FX3_API_KEY : ${{ secrets.ATLASCODE_FX3_API_KEY }}
@@ -60,40 +142,39 @@ jobs:
60142
61143 steps :
62144 - uses : actions/checkout@v4
145+
63146 - uses : actions/setup-node@v4
64147 with :
65148 node-version : 20
66- cache : ' npm'
67-
68- - name : Install dependencies
69- run : npm ci --no-audit
149+
150+ - name : Download node_modules
151+ uses : actions/download-artifact@v4
152+ with :
153+ name : node-modules
70154
71- - name : Run unit tests
72- if : matrix.kind == 'unit'
73- run : npm run test
155+ - name : Extract node_modules
156+ run : tar -xzf node_modules.tar.gz
74157
75- - name : Build and package the extension
76- if : matrix.kind == 'e2e'
77- run : npm run extension:package
158+ - name : Download extension package
159+ uses : actions/download-artifact@v4
160+ with :
161+ name : extension-package
78162
79163 - name : Generate SSL certs for E2E test
80- if : matrix.kind == 'e2e'
81164 run : npm run test:e2e:sslcerts
82165
83166 - name : Fetch E2E image
84- if : matrix.kind == 'e2e'
85167 run : |
86168 docker pull ghcr.io/atlassian/atlascode-e2e:latest
87169 docker tag ghcr.io/atlassian/atlascode-e2e:latest atlascode-e2e
88170
89171 - name : Run E2E (${{ matrix.target }})
90- if : matrix.kind == 'e2e'
91172 run : npm run test:e2e:docker
92173 env :
93174 TARGET : ${{ matrix.target }}
94175
95176 - name : Upload E2E artifacts (${{ matrix.target }})
96- if : matrix.kind == 'e2e' && failure()
177+ if : failure()
97178 uses : actions/upload-artifact@v4
98179 with :
99180 name : e2e-test-results-${{ matrix.target }}
@@ -102,14 +183,35 @@ jobs:
102183 if-no-files-found : ignore
103184
104185 finalize :
105- needs : [ci-matrix ]
186+ needs : [setup-dependencies, lint, test-unit, build-extension, test-e2e ]
106187 runs-on : ubuntu-latest
107188 if : always()
108189 steps :
190+ - name : Delete node_modules artifact
191+ if : ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
192+ uses : geekyeggo/delete-artifact@v5
193+ with :
194+ name : node-modules
195+ failOnError : false
196+
197+ - name : Delete extension package artifact
198+ if : ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
199+ uses : geekyeggo/delete-artifact@v5
200+ with :
201+ name : extension-package
202+ failOnError : false
203+
109204 - name : Check if all jobs succeeded
110205 run : |
111- if [[ "${{ needs.ci-matrix.result }}" != "success" ]]; then
112- echo "One of the ci-matrix jobs failed"
206+ results='${{ toJSON(needs.*.result) }}'
207+ if echo "$results" | jq -e 'any(. != "success")' > /dev/null; then
208+ echo "One or more jobs failed:"
209+ echo " setup-dependencies: ${{ needs.setup-dependencies.result }}"
210+ echo " lint: ${{ needs.lint.result }}"
211+ echo " test-unit: ${{ needs.test-unit.result }}"
212+ echo " build-extension: ${{ needs.build-extension.result }}"
213+ echo " test-e2e: ${{ needs.test-e2e.result }}"
214+ echo "Artifacts are retained for 1 day to allow rerunning failed jobs"
113215 exit 1
114216 fi
115- echo "All steps completed successfully"
217+ echo "All steps completed successfully"
0 commit comments