Repository navigation
127 lines (113 loc) · 4.47 KB
/
Copy pathsync-examples.yml
File metadata and controls
127 lines (113 loc) · 4.47 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
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
# ──────────────────────────────────────────────────────────────────────
# Sync examples + README + branding assets to mshobeyri/multimeter-examples
# ──────────────────────────────────────────────────────────────────────
# Source of truth: this repo (multimeter).
# Target: https://github.com/mshobeyri/multimeter-examples
#
# Branch mapping:
# multimeter `main` → multimeter-examples `main`
# multimeter `dev` → multimeter-examples `dev`
#
# Required secret on multimeter:
# EXAMPLES_REPO_TOKEN — PAT (classic: repo scope, or fine-grained:
# Contents: Read and write on mshobeyri/multimeter-examples)
# ──────────────────────────────────────────────────────────────────────
name: Sync examples repo
on:
push:
branches: [main, dev]
paths:
- 'examples/**'
- 'README.md'
- 'res/logo.png'
- 'res/logo.svg'
- 'res/logo_file.svg'
- 'res/intro.png'
- 'res/demo.png'
- 'res/demo.gif'
- 'res/website.png'
- 'res/request_feature.png'
- '.github/workflows/sync-examples.yml'
workflow_dispatch:
concurrency:
group: sync-examples-${{ github.ref_name }}
cancel-in-progress: true
jobs:
sync:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
runs-on: ubuntu-latest
env:
TARGET_BRANCH: ${{ github.ref_name }}
steps:
- name: Checkout multimeter
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Check token
env:
TOKEN: ${{ secrets.EXAMPLES_REPO_TOKEN }}
run: |
if [ -z "${TOKEN}" ]; then
echo "::error::Missing secret EXAMPLES_REPO_TOKEN (PAT with write access to mshobeyri/multimeter-examples)."
exit 1
fi
- name: Clone examples repo
env:
TOKEN: ${{ secrets.EXAMPLES_REPO_TOKEN }}
run: |
set -euo pipefail
REMOTE="https://x-access-token:${TOKEN}@github.com/mshobeyri/multimeter-examples.git"
if git ls-remote --heads "${REMOTE}" "${TARGET_BRANCH}" | grep -q "refs/heads/${TARGET_BRANCH}$"; then
git clone --depth 1 --branch "${TARGET_BRANCH}" "${REMOTE}" /tmp/multimeter-examples
else
git clone --depth 1 "${REMOTE}" /tmp/multimeter-examples
git -C /tmp/multimeter-examples checkout -B "${TARGET_BRANCH}"
fi
- name: Sync content
run: |
set -euo pipefail
DEST=/tmp/multimeter-examples
# examples/ (full replace of that tree)
rsync -a --delete \
--exclude '.DS_Store' \
--exclude '**/.DS_Store' \
examples/ "${DEST}/examples/"
# Root README
cp README.md "${DEST}/README.md"
# Branding / README assets
mkdir -p "${DEST}/res"
for f in \
logo.png \
logo.svg \
logo_file.svg \
intro.png \
demo.png \
demo.gif \
website.png \
request_feature.png
do
if [ -f "res/${f}" ]; then
cp "res/${f}" "${DEST}/res/${f}"
else
echo "::warning::Missing source asset res/${f}"
fi
done
- name: Commit and push
working-directory: /tmp/multimeter-examples
env:
TOKEN: ${{ secrets.EXAMPLES_REPO_TOKEN }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to sync."
exit 0
fi
SHORT_SHA="${GITHUB_SHA::7}"
git commit -m "Sync from multimeter@${SHORT_SHA} (${TARGET_BRANCH})"
# Drop checkout's GITHUB_TOKEN extraheader so the PAT is what GitHub sees.
git remote set-url origin \
"https://x-access-token:${TOKEN}@github.com/mshobeyri/multimeter-examples.git"
git -c http.https://github.com/.extraheader= push origin "HEAD:${TARGET_BRANCH}"