Skip to content

Commit 87c2433

Browse files
Merge pull request #22 from dennisameling-org/add-ci-artifacts
ci: add ci-artifacts pipeline
2 parents 04079aa + db9a326 commit 87c2433

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

.github/workflows/ci-artifacts.yml

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: ci-artifacts
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
# For the continuous `ci-artifacts` release
10+
permissions:
11+
contents: write
12+
13+
env:
14+
LC_CTYPE: C.UTF-8
15+
16+
jobs:
17+
minimal-sdk-artifact:
18+
if: github.event.repository.fork == false
19+
runs-on: [Windows, ARM64]
20+
steps:
21+
- name: clone git-sdk-arm64
22+
run: |
23+
git init --bare git-sdk-arm64.git &&
24+
git --git-dir=git-sdk-arm64.git remote add origin https://github.com/${{github.repository}} &&
25+
git --git-dir=git-sdk-arm64.git config remote.origin.promisor true &&
26+
git --git-dir=git-sdk-arm64.git config remote.origin.partialCloneFilter blob:none &&
27+
git --git-dir=git-sdk-arm64.git fetch --depth=1 origin ${{github.sha}} &&
28+
git --git-dir=git-sdk-arm64.git update-ref --no-deref HEAD ${{github.sha}}
29+
- name: clone build-extra
30+
run: git clone --depth=1 --single-branch -b main https://github.com/git-for-windows/build-extra
31+
- name: build git-sdk-arm64-minimal-sdk
32+
shell: bash
33+
run: |
34+
sh -x ./build-extra/please.sh create-sdk-artifact --sdk=git-sdk-arm64.git minimal-sdk &&
35+
cygpath -aw minimal-sdk/usr/bin >>$GITHUB_PATH
36+
- name: compress artifact
37+
shell: bash
38+
run: mkdir artifacts && (cd minimal-sdk && tar cvf - * .[0-9A-Za-z]*) | gzip -1 >artifacts/git-sdk-aarch64-minimal.tar.gz
39+
- name: create zip and 7z SFX variants of the minimal SDK
40+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
41+
shell: bash
42+
run: |
43+
for path in clangarm64/bin/7z.exe clangarm64/bin/7z.dll clangarm64/lib/7zip/7zCon.sfx clangarm64/bin/libc++.dll
44+
do
45+
git --git-dir=git-sdk-arm64.git show HEAD:$path >${path##*/}
46+
done &&
47+
(cd minimal-sdk && ../7z.exe a -mmt=on -mx9 ../artifacts/git-sdk-aarch64-minimal.zip * .?*) &&
48+
(cd minimal-sdk && ../7z.exe a -t7z -mmt=on -m0=lzma -mqs -mlc=8 -mx=9 -md=256M -mfb=273 -ms=256M -sfx../7zCon.sfx \
49+
../artifacts/git-sdk-aarch64-minimal.7z.exe * .?*)
50+
- name: run some tests
51+
shell: bash
52+
run: |
53+
set -x
54+
. /etc/profile
55+
56+
# cygpath works
57+
test "$(cygpath -aw /)" = "${{github.workspace}}\minimal-sdk" || exit 1
58+
59+
# comes with Clang and can compile a DLL
60+
test "$(type -p clang)" = "/clangarm64/bin/clang" || exit 1
61+
cat >dll.c <<-\EOF &&
62+
__attribute__((dllexport)) int increment(int i)
63+
{
64+
return i + 1;
65+
}
66+
EOF
67+
68+
clang -Wall -g -O2 -shared -o sample.dll dll.c || exit 1
69+
ls -la
70+
71+
# stat works
72+
test "stat is /usr/bin/stat" = "$(type stat)" || exit 1
73+
stat /usr/bin/stat.exe || exit 1
74+
75+
# unzip works
76+
test "unzip is /usr/bin/unzip" = "$(type unzip)" || exit 1
77+
git init unzip-test &&
78+
echo TEST >unzip-test/README &&
79+
git -C unzip-test add -A &&
80+
git -C unzip-test -c user.name=A -c [email protected] commit -m 'Testing, testing...' &&
81+
git --git-dir=unzip-test/.git archive -o test.zip HEAD &&
82+
unzip -v test.zip >unzip-test.out &&
83+
cat unzip-test.out &&
84+
test "grep is /usr/bin/grep" = "$(type grep)" || exit 1
85+
grep README unzip-test.out
86+
- name: publish release assets
87+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
88+
uses: actions/github-script@v7
89+
with:
90+
script: |
91+
process.chdir('artifacts')
92+
const req = { owner: context.repo.owner, repo: context.repo.repo }
93+
// find or create the GitHub release named `ci-artifacts`
94+
const release = await (async () => {
95+
try {
96+
return await github.rest.repos.getReleaseByTag({ ...req, tag: 'ci-artifacts' });
97+
} catch (e) {
98+
if (e.status === 404) {
99+
// create the `ci-artifacts` GitHub release based on the current revision
100+
const workflowRunsURL = `${context.serverUrl}/${
101+
process.env.GITHUB_WORKFLOW_REF.replace(/\/\.github\/workflows\/([^@]+).*/, '/actions/workflows/$1')
102+
}`
103+
return await github.rest.repos.createRelease({
104+
... req,
105+
tag_name: 'ci-artifacts',
106+
body: `Continuous release of \`ci-artifacts\`
107+
108+
This release is automatically updated by the [ci-artifacts](${workflowRunsURL}) workflow.
109+
110+
For technical reasons, allow up to a minute for release assets to be missing while they are updated.`,
111+
});
112+
}
113+
throw e;
114+
}
115+
})()
116+
117+
const fs = require('fs')
118+
for (const fileName of [
119+
'git-sdk-aarch64-minimal.tar.gz',
120+
'git-sdk-aarch64-minimal.zip',
121+
'git-sdk-aarch64-minimal.7z.exe',
122+
]) {
123+
console.log(`Uploading ${fileName}`)
124+
const uploadReq = {
125+
...req,
126+
release_id: release.data.id,
127+
name: fileName,
128+
headers: {
129+
'content-length': (await fs.promises.stat(fileName)).size,
130+
},
131+
data: fs.createReadStream(fileName),
132+
}
133+
134+
// if the asset does not yet exist, simply upload it
135+
const originalAsset = release.data.assets.filter(asset => asset.name === fileName).pop()
136+
if (!originalAsset) {
137+
const asset = await github.rest.repos.uploadReleaseAsset(uploadReq)
138+
console.log(`Uploaded to ${asset.data.browser_download_url}`)
139+
continue
140+
}
141+
142+
// otherwise upload it using a temporary file name,
143+
// then delete the old asset
144+
// and then rename the new asset;
145+
// this way, the asset is not missing for a long time
146+
const asset = await github.rest.repos.uploadReleaseAsset({ ...uploadReq, name: `tmp.${fileName}` })
147+
await github.rest.repos.deleteReleaseAsset({ ...req, asset_id: originalAsset.id })
148+
const updatedAsset = await github.rest.repos.updateReleaseAsset({...req,
149+
asset_id: asset.data.id,
150+
name: fileName,
151+
label: fileName,
152+
})
153+
console.log(`Updated ${updatedAsset.data.browser_download_url}`)
154+
}
155+
156+
await github.rest.git.updateRef({
157+
...req,
158+
ref: 'tags/ci-artifacts',
159+
sha: process.env.GITHUB_SHA,
160+
})

0 commit comments

Comments
 (0)