Skip to content

Commit 78bb53f

Browse files
committed
ci: generate preview by pr
1 parent 31de1e7 commit 78bb53f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/gen_preview.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Generate Image Preview
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
paths:
8+
- 'content/**'
9+
10+
# cancel in-progress runs on new commits to same PR (github.event.number)
11+
concurrency:
12+
group: gen_preview_image${{ github.workflow }}-${{ github.event.number || github.sha }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
generate-preview:
17+
runs-on: ubuntu-latest
18+
name: Generate Preview Image
19+
permissions: # Job-level permissions configuration starts here
20+
contents: write # 'write' access to repository contents
21+
pull-requests: write # 'write' access to pull requests
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
26+
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
27+
# Download bin of gen_preview
28+
# TODO
29+
30+
- name: Get changed files
31+
run: |
32+
files=$(git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD main))
33+
preview ./crates/preview/assets/bg_preview.png ./public/previews $files
34+
- name: Commit changes
35+
run: |
36+
git config --global user.name 'github-actions[bot]'
37+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
38+
git add -A
39+
git commit -m "chore: generate opengraph image" || echo "No changes to commit"
40+
41+
- uses: ad-m/github-push-action@master
42+
with:
43+
branch: ${{ github.head_ref }}
44+

0 commit comments

Comments
 (0)