-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (124 loc) · 4.93 KB
/
test.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
142
143
144
145
146
147
148
149
150
151
152
name: Tests
on:
pull_request:
branches:
- main
- alpha
- beta
# Allow workflow to be called by another workflow
workflow_call:
# Must define secrets here so that the calling workflow can pass in the NPM_TOKEN needed to install private packages.
secrets:
NPM_TOKEN:
description: 'The NPM_TOKEN passed from the caller workflow as it is not available within workflow_call.'
required: true
VITE_AUTH_URL:
description: 'The base URL of the KAuth backend, e.g. https://global.api.konghq.tech'
required: true
# Allow workflow to be called manually
workflow_dispatch:
inputs:
VITE_AUTH_URL:
description: 'The base URL of the KAuth backend, e.g. https://global.api.konghq.tech'
type: string
default: https://global.api.konghq.tech
required: false
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Remove preview consumption comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_preview_consumption
delete: true
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Stylelint
run: yarn stylelint
- name: Lint
run: yarn lint
- name: Typecheck
run: yarn typecheck
- name: Build
if: github.event_name == 'pull_request'
run: yarn build
- name: Create .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLIC_PUBLISH }}
# Reference the env variable NPM_TOKEN here, not the secret
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
- name: Publish package preview
id: package-preview
# Do not run for `alpha` or `beta` branches
if: github.event_name == 'pull_request' && github.actor != 'renovate[bot]' && !contains(github.head_ref || github.ref_name, 'alpha') && !contains(github.head_ref || github.ref_name, 'beta')
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLIC_PUBLISH }}
run: |
git config user.email "konnectx-engineers+kongponents-bot@konghq.com"
git config user.name "Kong UI Bot"
preid="pr.${{ github.event.pull_request.number }}.$(git rev-parse --short ${{ github.event.pull_request.head.sha }})"
tag="pr-${{ github.event.pull_request.number }}"
echo "preid=${preid}"
git checkout ${{ github.head_ref }}
yarn version --prerelease --preid ${preid} --allow-branch ${{ github.head_ref }} --no-git-tag-version --yes --amend
package_version=$(jq -r ".version" package.json)
package=@kong/kong-auth-elements@"${package_version}"
npm show "${package}" >/dev/null 2>&1 && npm_show_status=0 || npm_show_status=1
if [ $npm_show_status -eq 0 ]; then
echo "Package ${package} is already published. Skipping publishing."
exit 0
fi
npm_instructions=""
pkg=$(npm publish --no-git-checks --access public --report-summary --tag "${tag}" | grep "+ "| sed 's/+ //')
if [[ -z "${pkg}" ]]; then
echo "Error publishing package"
exit -1
fi
npm_instructions="@$(echo ${pkg}|cut -d'@' -f2)@${tag}"
echo "npm_instructions<<EOF" >> $GITHUB_OUTPUT
echo -e "$npm_instructions" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Provide preview link info
if: ${{ steps.package-preview.outputs.npm_instructions != '' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_preview_consumption
message: |
### Install the preview package from this PR in your consuming application
In your host project, you may install the preview package version generated by this PR:
```sh
${{ steps.package-preview.outputs.npm_instructions }}
```
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}
- name: Run Cypress component tests
uses: cypress-io/github-action@v6
with:
install: false
command: yarn test
env:
VITE_AUTH_URL: ${{ secrets.VITE_AUTH_URL || inputs.VITE_AUTH_URL }}
- name: Upload Cypress screenshots (on failure)
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress_screenshots
path: cypress/screenshots/
- name: Upload Cypress videos (always)
uses: actions/upload-artifact@v4
if: always()
with:
name: cypress_videos
path: cypress/videos/