-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (130 loc) · 4.81 KB
/
ci.yml
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
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: CI
on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]
jobs:
setup:
runs-on: ubuntu-latest
outputs:
git_source_branch: ${{ steps.variables.outputs.git_source_branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
- name: Define variables
id: variables
shell: bash
run: |
GIT_SOURCE_BRANCH=`([ "${GITHUB_HEAD_REF}" != "" ] && echo "${GITHUB_HEAD_REF}" || echo "${GITHUB_REF}") | sed 's/refs\/heads\///g'`
echo "git_source_branch=$GIT_SOURCE_BRANCH" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [ setup ]
strategy:
matrix:
node-version: [ 20 ]
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: Find diffs
if: failure() && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
id: snapshots_diffs
shell: bash
run: |
echo "found=$(find . -iname '*.diff.png' | wc -l)" >> $GITHUB_OUTPUT
- name: update snapshots
if: ${{ always() && steps.snapshots_diffs.outputs.found > 0 }}
run: npm run test:cypress:ci:update
- name: Create Pull Request
id: update_snapshots
if: always() && steps.snapshots_diffs.outputs.found > 0 && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
env:
HASH: ${{ format('#{0}', github.event.number) }}
BRANCH: ${{ needs.setup.outputs.git_source_branch }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: ${{ env.BRANCH }}
branch: snapshots-patch/${{ env.BRANCH }}
title: Update Cypress snapshots in ${{ env.BRANCH }}
commit-message: Updated snapshots
body: Updated snapshots in ${{ github.event_name == 'pull_request' && env.HASH || env.BRANCH}}
uses: peter-evans/create-pull-request@v4
- name: Comment PR
if: ${{ always() && github.event_name == 'pull_request' && steps.update_snapshots.outputs.pull-request-number }}
uses: thollander/actions-comment-pull-request@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: '${{ steps.update_snapshots.outputs.pull-request-operation }}: #${{ steps.update_snapshots.outputs.pull-request-number }}'
- uses: codecov/codecov-action@v3
- name: Store test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
cypress/**/__image_snapshots__/**/*.diff.*
cypress/**/__image_snapshots__/**/*.actual.*
cypress/screenshots/
cypress/videos/
if-no-files-found: ignore
release:
name: Release
needs: [ "build" ]
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
# docs:
# runs-on: ubuntu-latest
# needs: [ "build", "release" ]
# if: ${{ github.ref == 'refs/heads/master' }}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 20
# - uses: actions/cache@v3
# with:
# path: |
# **/node_modules
# key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
# - run: npm ci
# - run: npm run deploy-storybook -- --ci --host-token-env-variable=GITHUB_TOKEN
# env:
# GITHUB_TOKEN: JulianWielga:${{ secrets.GITHUB_TOKEN }}