-
Notifications
You must be signed in to change notification settings - Fork 37
101 lines (89 loc) · 3.67 KB
/
split.yml
File metadata and controls
101 lines (89 loc) · 3.67 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
name: Split Packages
on:
push:
branches: [main, develop]
tags: ['[0-9]*']
concurrency:
group: split-${{ github.ref }}
cancel-in-progress: false
env:
SPLIT_ORG: marko-php
jobs:
setup:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.list.outputs.packages }}
steps:
- uses: actions/checkout@v6
- name: List packages
id: list
run: |
packages=$(ls packages/ | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "packages=$packages" >> $GITHUB_OUTPUT
split:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
package: ${{ fromJson(needs.setup.outputs.packages) }}
fail-fast: false
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- name: Configure git
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
- name: Install splitsh-lite
run: |
curl -sL https://github.com/splitsh/lite/releases/download/v1.0.1/lite_linux_amd64.tar.gz | tar xz
sudo mv splitsh-lite /usr/local/bin/splitsh-lite
- name: Split and push
env:
SPLIT_TOKEN: ${{ secrets.SPLIT_TOKEN }}
run: |
REPO="https://x-access-token:${SPLIT_TOKEN}@github.com/${SPLIT_ORG}/marko-${{ matrix.package }}.git"
SHA=$(splitsh-lite --prefix="packages/${{ matrix.package }}")
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG="${GITHUB_REF#refs/tags/}"
git push --force "$REPO" "${SHA}:refs/heads/main"
git push --force "$REPO" "${SHA}:refs/tags/${TAG}"
else
BRANCH="${GITHUB_REF#refs/heads/}"
git push --force "$REPO" "${SHA}:refs/heads/${BRANCH}"
fi
- name: Notify Packagist
if: startsWith(github.ref, 'refs/tags/')
env:
PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }}
run: |
PKG_URL="https://github.com/${SPLIT_ORG}/marko-${{ matrix.package }}"
# Try to update first. If Packagist returns 404 the package isn't
# registered yet — self-heal by calling create-package, then retry
# the update so the new tag actually gets indexed. This removes
# the manual `register-packagist.sh` step from the new-package
# workflow: contributors can add `packages/foo/` via PR and the
# first release tag will register + publish it automatically.
HTTP=$(curl -s -o /tmp/packagist_resp -w "%{http_code}" \
-X POST https://packagist.org/api/update-package \
-H "Content-Type: application/json" \
-H "Authorization: Bearer markshust:${PACKAGIST_TOKEN}" \
-d "{\"repository\":\"${PKG_URL}\"}")
if [[ "$HTTP" == "404" ]]; then
echo "marko/${{ matrix.package }} not registered on Packagist — registering now..."
curl -sf -X POST \
"https://packagist.org/api/create-package?username=markshust&apiToken=${PACKAGIST_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"repository\":{\"url\":\"${PKG_URL}\"}}"
echo "Registered. Re-running update so the tag gets indexed..."
curl -sf -X POST https://packagist.org/api/update-package \
-H "Content-Type: application/json" \
-H "Authorization: Bearer markshust:${PACKAGIST_TOKEN}" \
-d "{\"repository\":\"${PKG_URL}\"}"
elif [[ "$HTTP" -ge 400 ]]; then
echo "Packagist update failed with HTTP ${HTTP}:"
cat /tmp/packagist_resp
exit 1
fi