Skip to content

Commit faec215

Browse files
authored
refactor(test): auto-commit regenerated snapshots (#4321)
1 parent 4fcf881 commit faec215

File tree

4 files changed

+126
-4
lines changed

4 files changed

+126
-4
lines changed

.github/workflows/00-init.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ jobs:
1717
ASSET_INIT_VECTOR: ${{ secrets.ASSET_INIT_VECTOR }}
1818
ASSET_PASSWORD: ${{ secrets.ASSET_PASSWORD }}
1919

20+
# - name: 🚮 Dump GitHub context for debugging
21+
# env:
22+
# GITHUB_CONTEXT: ${{ toJson(github) }}
23+
# run: echo "$GITHUB_CONTEXT"
24+
2025
- name: 💀 Killing me softly
2126
uses: ./.github/actions/cancel-workflow
2227
if: failure()

.github/workflows/02-e2e-regenerate.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ jobs:
9090
with:
9191
name: snapshots-${{ inputs.type }}
9292
path: ./__snapshots__/*/component
93-
retention-days: 30
93+
retention-days: 7
9494

9595
- name: 🆙 Upload foundations
9696
if: always() && inputs.type == 'foundations'
9797
uses: actions/upload-artifact@v4
9898
with:
9999
name: snapshots-${{ inputs.type }}
100100
path: ./__snapshots__/foundations
101-
retention-days: 30
101+
retention-days: 7
102102

103103
- name: 🆙 Upload patternhub
104104
if: always() && inputs.type == 'patternhub'
105105
uses: actions/upload-artifact@v4
106106
with:
107107
name: snapshots-${{ inputs.type }}
108108
path: ./__snapshots__/*/patternhub
109-
retention-days: 30
109+
retention-days: 7
110110

111111
- name: 🆙 Upload showcase
112112
if: always() && inputs.type == 'showcases'
113113
uses: actions/upload-artifact@v4
114114
with:
115115
name: snapshots-${{ inputs.type }}
116116
path: ./__snapshots__/*/showcase
117-
retention-days: 30
117+
retention-days: 7
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Commit Regenerated Snapshots
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
components:
7+
description: "Regenerate snapshots for components"
8+
required: true
9+
type: boolean
10+
foundations:
11+
description: "Regenerate snapshots for foundations"
12+
required: true
13+
type: boolean
14+
patternhub:
15+
description: "Regenerate snapshots for patternhub"
16+
required: true
17+
type: boolean
18+
showcases:
19+
description: "Regenerate snapshots for showcases"
20+
required: true
21+
type: boolean
22+
23+
jobs:
24+
commit-showcases:
25+
name: 🆙 Commit regenerated snapshots
26+
if: (inputs.showcases || inputs.components || inputs.foundations || inputs.patternhub) && !contains(github.actor,'[bot]')
27+
runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly
28+
permissions:
29+
contents: write
30+
pull-requests: write
31+
env:
32+
NEW_PR_BRANCH: "${{ github.head_ref }}-auto"
33+
steps:
34+
- name: ⏬ Checkout repo
35+
uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.head_ref }}
38+
39+
- name: ⏬ Download components
40+
uses: actions/download-artifact@v4
41+
# Only download artifact if the artifact exists
42+
if: inputs.components
43+
with:
44+
name: snapshots-components
45+
path: ./__snapshots__/
46+
47+
- name: ⏬ Download foundations
48+
uses: actions/download-artifact@v4
49+
# Only download artifact if the artifact exists
50+
if: inputs.foundations
51+
with:
52+
name: snapshots-foundations
53+
path: ./__snapshots__/
54+
55+
- name: ⏬ Download patternhub
56+
uses: actions/download-artifact@v4
57+
if: inputs.patternhub
58+
with:
59+
name: snapshots-patternhub
60+
path: ./__snapshots__/
61+
62+
- name: ⏬ Download showcase
63+
uses: actions/download-artifact@v4
64+
if: inputs.showcases
65+
with:
66+
name: snapshots-showcases
67+
path: ./__snapshots__/
68+
69+
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow
70+
- name: 🧬 Generate a token
71+
id: generate-token
72+
uses: actions/create-github-app-token@v2
73+
with:
74+
app-id: ${{ vars.AUTO_MERGE_APP_ID }}
75+
private-key: ${{ secrets.AUTO_MERGE_PRIVATE_KEY }}
76+
77+
- name: 🏗️ Create new branch and commit changes
78+
env:
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
run: |
81+
git config --global user.name "github-actions[bot]"
82+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
83+
84+
git checkout -b "$NEW_PR_BRANCH"
85+
git add __snapshots__/*
86+
87+
# We can't use semantic commits here because of the if statement in the workflow
88+
git commit --no-verify -m "auto update snapshots"
89+
git push -f origin "$NEW_PR_BRANCH"
90+
91+
- name: 🪗 Create Pull Request
92+
env:
93+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
run: |
95+
gh pr create --base ${{ github.head_ref }} --head "$NEW_PR_BRANCH" --title "Automated PR: Auto update snapshots" --body "This PR was created automatically by a GitHub Action."
96+
97+
- name: 🤖 Squash the PR
98+
run: gh pr merge --squash "$NEW_PR_BRANCH"
99+
env:
100+
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

.github/workflows/default.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,23 @@ jobs:
190190
get-playwright-version
191191
]
192192

193+
commit-regenerated-snapshots:
194+
uses: ./.github/workflows/02-e2e-regenerated-snapshots-commit.yml
195+
secrets: inherit
196+
if: always()
197+
needs:
198+
[
199+
regenerate-snapshots-components,
200+
regenerate-snapshots-foundations,
201+
regenerate-snapshots-patternhub,
202+
regenerate-snapshots
203+
]
204+
with:
205+
showcases: ${{ needs.regenerate-snapshots.result == 'success' }}
206+
components: ${{ needs.regenerate-snapshots-components.result == 'success' }}
207+
foundations: ${{ needs.regenerate-snapshots-foundations.result == 'success' }}
208+
patternhub: ${{ needs.regenerate-snapshots-patternhub.result == 'success' }}
209+
193210
checks-done:
194211
if: ${{ always() }}
195212
runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly

0 commit comments

Comments
 (0)