-
Notifications
You must be signed in to change notification settings - Fork 31
199 lines (170 loc) · 7.44 KB
/
pull_request.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Pull request
on:
pull_request:
branches: ["main"]
merge_group:
types: [checks_requested]
run-name: Bygg og test ${{ github.event_name == 'merge_group' && github.event.merge_group.head_commit.message || github.event.pull_request.title }}
env:
PREVIEW_PATH: preview/${{ github.event.pull_request.head.ref }}
PREFIX_PATHS: true
jobs:
build:
name: Sjekk for endringer og bygg pakker
if: ${{ !contains(github.event.sender.login, 'fremtind-bot') }}
outputs:
preview: ${{ steps.changes.outputs.preview }}
testlint: ${{ steps.changes.outputs.testlint }}
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check for changes that require extra verification
if: ${{ github.event_name != 'merge_group' }}
uses: ./actions/paths-filter
id: changes
with:
filters: |
testlint:
- "**/*.js"
- "**/*.scss"
- "**/*.ts"
- "**/*.tsx"
- "**/vite.test.config.mjs"
- "pnpm-lock.yaml"
preview:
- "packages/**/*.scss"
- "packages/core/**/!(*.d|*.test).ts"
- "packages/core/**/!(*.test).tsx"
- "packages/*-react/**/!(*.d|*.test).ts"
- "packages/*-react/**/!(*.test).tsx"
- "pnpm-lock.yaml"
- "packages/**/*.mdx"
- "portal/src/texts/**"
- name: Setup pnpm
if: steps.changes.outputs.has_matches == 'true' || github.event_name == 'merge_group'
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v3
if: steps.changes.outputs.has_matches == 'true' || github.event_name == 'merge_group'
with:
node-version: 18
cache: "pnpm"
- name: Restore Monorepo Runner Cache
if: github.event_name == 'merge_group'
uses: actions/cache/restore@v3
with:
path: .nx
key: nx-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
restore-keys: |
nx-${{ hashFiles('pnpm-lock.yaml') }}-
- name: Cache Monorepo Runner
if: github.event_name == 'pull_request' && steps.changes.outputs.has_matches == 'true'
uses: actions/cache@v3
with:
path: .nx
key: nx-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
restore-keys: |
nx-${{ hashFiles('pnpm-lock.yaml') }}-
- name: Install dependencies
if: steps.changes.outputs.has_matches == 'true' || github.event_name == 'merge_group'
run: pnpm install
- name: Build packages
if: steps.changes.outputs.has_matches == 'true' || github.event_name == 'merge_group'
run: pnpm build
preview:
name: Publiser forhåndsvisning
needs: [build]
if: github.event_name != 'merge_group' && needs.build.outputs.preview == 'true'
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"
- name: Restore Monorepo Runner Cache
uses: actions/cache/restore@v3
with:
path: .nx
key: nx-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
restore-keys: |
nx-${{ hashFiles('pnpm-lock.yaml') }}-
# Steget må være med, men vil være cachet
- name: Install dependencies
run: pnpm install
- name: Build packages
run: pnpm build
- name: Add a comment with a link to the preview
uses: marocchino/sticky-pull-request-comment@da224cb0e3c8b27cae68d40c93649421b5b93e45
with:
header: preview
GITHUB_TOKEN: ${{ secrets.FREMTIND_BOT_ACCESS_TOKEN }}
message: |
<span aria-hidden="true">🔄</span> **Gjør klar en forhåndsvisning…**
<span aria-hidden="true">🔍</span> Commit: ${{ github.sha }}
- name: Build site
env:
GATSBY_MIXPANEL_PROJECT_ID: ${{ secrets.MIXPANEL_PROJECT_ID_TEST }}
run: pnpm build:docs
- name: Deploy preview
env:
GH_TOKEN: ${{ secrets.BOT_PUBLISH_TOKEN }}
run: |
git config user.email "[email protected]"
git config user.name "fremtind-bot"
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/fremtind/jokul.git
pnpm gh-pages --add --dist portal/public --dest ${{ env.PREVIEW_PATH }} --message "docs: preview #${{ github.event.number }}"
- name: Add a comment with a link to the preview
uses: marocchino/sticky-pull-request-comment@da224cb0e3c8b27cae68d40c93649421b5b93e45
with:
header: preview
GITHUB_TOKEN: ${{ secrets.FREMTIND_BOT_ACCESS_TOKEN }}
message: |
<span aria-hidden="true">✅</span> Forhåndsvisning: https://jokul.fremtind.no/${{ env.PREVIEW_PATH }}/
<span aria-hidden="true">🔍</span> Commit: ${{ github.sha }}
Forhåndsvisningen blir tilgjengelig innen et par minutter. Den fjernes automatisk når pull requesten lukkes.
testlint:
name: Kjør tester og linting
needs: [build]
if: github.event_name == 'merge_group' || (needs.build.outputs.testlint == 'true' && !contains(github.event.sender.login, 'fremtind-bot'))
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"
- name: Restore Monorepo Runner Cache
uses: actions/cache/restore@v3
with:
path: .nx
key: nx-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
restore-keys: |
nx-${{ hashFiles('pnpm-lock.yaml') }}-
# Steget må være med, men vil være cachet
- name: Install dependencies
run: pnpm install
- name: Build packages
run: pnpm build
- name: Lint and test
run: pnpm ci:test