Repository navigation
63 lines (56 loc) · 2.17 KB
/
Copy pathupdate_demo.yml
File metadata and controls
63 lines (56 loc) · 2.17 KB
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
name: Update Demo
on:
push:
branches:
- main
env:
TEMPLATE: cookiecutter-python-package
CURRENT_DEMO: cookiecutter-python-package-demo-current
DEMO: cookiecutter-python-package-demo
jobs:
update_demo:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ env.TEMPLATE }}
uses: actions/checkout@v7
with:
path: ${{ env.TEMPLATE }}
- name: Checkout ${{ env.DEMO }}
uses: actions/checkout@v7
with:
repository: "sgraaf/${{ env.DEMO }}"
token: ${{ secrets.X_GITHUB_PAT }}
path: ${{ env.CURRENT_DEMO }}
- name: Install the latest version of uv with caching enabled
id: setup-uv
uses: astral-sh/setup-uv@v10.2.0
with:
enable-cache: true
- name: Build Demo
run: |
cat "${{ env.TEMPLATE }}/.github/workflows/input-for-demo.txt" | uvx cookiecutter "${{ env.TEMPLATE }}"
find "${{ env.DEMO }}"
- name: Commit and push changes
run: |
# Sync the generated files into the checkout rather than moving `.git`: `actions/checkout` persists the
# credentials via an `includeIf "gitdir:..."` entry, which no longer matches once `.git` has been moved
rsync -a --delete --exclude .git "${{ env.DEMO }}/" "${{ env.CURRENT_DEMO }}/"
cd "${{ env.CURRENT_DEMO }}"
git config user.name "Automated"
git config user.email "actions@users.noreply.github.com"
git add -A
git commit -m "Demo of ${{ env.TEMPLATE }} @ ${GITHUB_SHA::7}" || exit 0
git push
- name: Post commit comment
run: |
export FULL_SHA=$(git rev-parse HEAD)
echo '{}' | \
jq --arg v "Demo: https://github.com/sgraaf/${{ env.DEMO }}/tree/${FULL_SHA::7}" '. + { body: $v }' | \
curl -sL \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments" \
-d @-
working-directory: ${{ env.CURRENT_DEMO }}