Skip to content

Commit 4a1eb33

Browse files
authored
Merge pull request #35 from code0-tech/25-pipeline-for-snapshot-regenerate
Add pipeline to regenerate image snapshots
2 parents 3c4ff65 + bd0be2c commit 4a1eb33

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI / Update Snapshots
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- labeled
7+
8+
permissions:
9+
pull-requests: write
10+
contents: write
11+
12+
jobs:
13+
pipeline:
14+
if: ${{ github.event.label.name == 'regenerate-snapshots' }}
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: Taucher2003/GitLab-Pipeline-Action@1.5.0
18+
name: Run pipeline
19+
id: pipeline
20+
with:
21+
GL_SERVER_URL: https://gitlab.com
22+
GL_PROJECT_ID: '52344025'
23+
GL_RUNNER_TOKEN: ${{ secrets.GL_RUNNER_TOKEN }}
24+
GL_API_TOKEN: ${{ secrets.GL_API_TOKEN }}
25+
SHOW_JOB_LOGS: all
26+
env:
27+
GLPA_C0_UPDATE_SNAPSHOTS: 'true'
28+
GLPA_C0_GH_PR_HEAD_URL: ${{ github.event.pull_request.head.repo.clone_url }}
29+
GLPA_C0_GH_PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
30+
GLPA_C0_GH_BOT_PUSH_ACCESS_TOKEN: ${{ secrets.GH_BOT_PUSH_ACCESS_TOKEN }}
31+
GLPA_C0_GH_BOT_PUSH_USERNAME: ${{ secrets.GH_BOT_PUSH_USERNAME }}
32+
- run: gh pr edit "${{ github.event.number }}" --remove-label "regenerate-snapshots"
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
GH_REPO: ${{ github.repository }}

.gitlab-ci.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ include:
33
ref: build-branch
44
file: ci-template.gitlab-ci.yml
55

6+
docs:
7+
rules:
8+
- if: $C0_UPDATE_SNAPSHOTS == null
9+
610
storybook:build:
711
image: node:20.9.0
812
stage: build
@@ -21,22 +25,29 @@ storybook:build:
2125
paths:
2226
- storybook-static
2327
expire_in: 7 days
28+
rules:
29+
- if: $C0_UPDATE_SNAPSHOTS == null
2430

25-
storybook:test:
31+
.storybook:test:base:
2632
image: ghcr.io/code0-tech/build-images/node-20.9-playwright:6.1
2733
stage: test
28-
script:
34+
before_script:
2935
- source ~/.asdf/asdf.sh
3036
- npm ci
3137
- npm run storybook:dev &
3238
- curl --fail -sv --retry 30 --retry-delay 3 --head --retry-all-errors http://127.0.0.1:6006
39+
40+
storybook:test:
41+
extends:
42+
- .storybook:test:base
43+
script:
3344
- npm run storybook:test:all -- --ci || exit_code=$?
3445
- |
3546
if [[ $exit_code -ne 0 && -d "__snapshots__/__diff_output__" ]]; then
3647
echo -e "\e[0Ksection_start:`date +%s`:glpa_summary\r\e[0KHeader of the summary"
3748
echo "Storybook tests failed."
3849
echo "Check for rendering differences at http://gitlab.com/code0-tech/pictor/-/jobs/$CI_JOB_ID/artifacts/browse/__snapshots__/__diff_output__/"
39-
echo "If the changes are intended, update the fixtures with npm run storybook:test:update"
50+
echo "If the changes are intended, update the snapshots by adding the 'regenerate-snapshots' label."
4051
echo -e "\e[0Ksection_end:`date +%s`:glpa_summary\r\e[0K"
4152
fi
4253
exit $exit_code
@@ -45,3 +56,26 @@ storybook:test:
4556
paths:
4657
- __snapshots__/__diff_output__
4758
expire_in: 7 days
59+
rules:
60+
- if: $C0_UPDATE_SNAPSHOTS == null
61+
62+
storybook:test:update:
63+
extends:
64+
- .storybook:test:base
65+
before_script:
66+
- git remote add github $C0_GH_PR_HEAD_URL
67+
- git fetch github
68+
- git checkout $C0_GH_PR_HEAD_REF
69+
- !reference [.storybook:test:base, before_script]
70+
script:
71+
- npm run storybook:test:update
72+
- git add __snapshots__
73+
- git config --global user.name "github-actions[bot]"
74+
- git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
75+
- git commit -m "Update image snapshots"
76+
- >
77+
git
78+
-c credential.helper='!f() { sleep 1; echo "username=${C0_GH_BOT_PUSH_USERNAME}"; echo "password=${C0_GH_BOT_PUSH_ACCESS_TOKEN}"; }; f'
79+
push github $C0_GH_PR_HEAD_REF
80+
rules:
81+
- if: $C0_UPDATE_SNAPSHOTS

0 commit comments

Comments
 (0)