Repository navigation
149 lines (143 loc) · 6.56 KB
/
Copy pathmonorepo-split-plan.yml
File metadata and controls
149 lines (143 loc) · 6.56 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Monorepo Split
on:
push:
branches: [main]
tags:
- 'v*'
paths:
- '.github/monorepo-split.json'
- '.github/scripts/monorepo-split-plan.php'
- '.github/workflows/monorepo-split-plan.yml'
- 'src/SonsOfPHP/**/composer.json'
- 'src/**'
pull_request:
branches: [main]
paths:
- '.github/monorepo-split.json'
- '.github/scripts/monorepo-split-plan.php'
- '.github/workflows/monorepo-split-plan.yml'
- 'src/SonsOfPHP/**/composer.json'
- 'src/**'
workflow_dispatch:
inputs:
base:
description: 'Base git ref for changed-package replay'
required: false
head:
description: 'Head git ref to check out and publish'
required: true
default: 'main'
tag:
description: 'Optional release tag to publish instead of a branch range'
required: false
publish:
description: 'Actually push split refs instead of calculating only'
required: true
type: boolean
default: false
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
plan:
name: Split packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
- uses: actions/setup-go@v7
with:
go-version: '1.22'
cache: false
- name: Install splitsh-lite
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake libssh2-1-dev libssl-dev pkg-config zlib1g-dev
curl -LsSf https://github.com/libgit2/libgit2/archive/refs/tags/v1.5.0.tar.gz | tar -xz
cmake -S libgit2-1.5.0 -B libgit2-1.5.0/build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/libgit2-1.5 \
-DBUILD_TESTS=OFF
cmake --build libgit2-1.5.0/build --parallel 2
sudo cmake --install libgit2-1.5.0/build
echo "PKG_CONFIG_PATH=/usr/local/libgit2-1.5/lib/pkgconfig" >> "$GITHUB_ENV"
echo "LD_LIBRARY_PATH=/usr/local/libgit2-1.5/lib" >> "$GITHUB_ENV"
export PKG_CONFIG_PATH=/usr/local/libgit2-1.5/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/libgit2-1.5/lib
GOBIN="$RUNNER_TEMP/bin" go install github.com/splitsh/lite@master
sudo mv "$RUNNER_TEMP/bin/lite" /usr/local/bin/splitsh-lite
splitsh-lite --help
- uses: actions/create-github-app-token@v3
id: app-token
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish)
with:
client-id: ${{ secrets.MONOREPO_SPLIT_APP_CLIENT_ID }}
private-key: ${{ secrets.MONOREPO_SPLIT_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
permission-contents: write
- name: Configure read-only repo token auth
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.publish)
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
echo "GIT_TERMINAL_PROMPT=0" >> "$GITHUB_ENV"
auth_header="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)"
git config --global http.https://github.com/.extraheader "$auth_header"
- name: Validate split config
run: php .github/scripts/monorepo-split-plan.php
- name: Plan pull request package splits
if: github.event_name == 'pull_request'
run: |
php .github/scripts/monorepo-split-plan.php \
--base='${{ github.event.pull_request.base.sha }}' \
--head='${{ github.event.pull_request.head.sha }}' \
--origin=HEAD \
--calculate-splits
- name: Publish mainline package splits
if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/')
run: |
php .github/scripts/monorepo-split-plan.php \
--base='${{ github.event.before }}' \
--head='${{ github.sha }}' \
--origin=HEAD \
--publish
- name: Publish release tag package splits
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
php .github/scripts/monorepo-split-plan.php \
--tag='${{ github.ref_name }}' \
--origin='${{ github.ref }}' \
--publish
- name: Run manual split replay
if: github.event_name == 'workflow_dispatch'
env:
BASE_REF: ${{ inputs.base }}
HEAD_REF: ${{ inputs.head }}
TAG_NAME: ${{ inputs.tag }}
PUBLISH_SPLITS: ${{ inputs.publish }}
run: |
if [ -n "$TAG_NAME" ]; then
git fetch --force origin "refs/tags/$TAG_NAME:refs/tags/$TAG_NAME"
command=(php .github/scripts/monorepo-split-plan.php --tag="$TAG_NAME" --origin="refs/tags/$TAG_NAME")
else
if [ -z "$BASE_REF" ]; then
echo "::error::Manual branch replay requires the base input."
exit 1
fi
git update-ref refs/heads/monorepo-split-replay-head "$HEAD_REF"
command=(php .github/scripts/monorepo-split-plan.php --base="$BASE_REF" --head="$HEAD_REF" --origin=refs/heads/monorepo-split-replay-head)
fi
if [ "$PUBLISH_SPLITS" = "true" ]; then
command+=(--publish)
else
command+=(--calculate-splits)
fi
"${command[@]}"