Skip to content

Commit 94a5385

Browse files
committed
Initial commit
0 parents  commit 94a5385

83 files changed

Lines changed: 29134 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitattributes‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Auto-detect text files, ensure they use LF.
2+
* text=auto eol=lf
3+
4+
# These files are always considered text and should use LF.
5+
# See core.whitespace @ http://git-scm.com/docs/git-config for whitespace flags.
6+
*.php text eol=lf whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
7+
*.json text eol=lf whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
8+
*.cmd text eol=crlf
9+
10+
# Native binaries and compressed fixtures
11+
/bin/zstd-extract-* binary
12+
*.zst binary
13+
*.tar binary
14+
15+
# Ignore these files in GitHub dists and `git archive` actions.
16+
/.gitattributes export-ignore
17+
/.github export-ignore
18+
/.gitignore export-ignore
19+
/native export-ignore
20+
/phpstan.neon.dist export-ignore
21+
/phpunit.xml.dist export-ignore
22+
/tests export-ignore
23+
/CONTRIBUTING.md export-ignore

‎.github/dependabot.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"
8+
cooldown:
9+
default-days: 7
10+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# Checks that bin/ is byte-identical to a fresh build (the zstd-extract-binaries artifact in $1).
3+
set -euo pipefail
4+
5+
built=$1
6+
fail=0
7+
for name in zstd-extract-linux-x86_64 zstd-extract-linux-aarch64 zstd-extract-darwin zstd-extract-windows-x86_64.exe; do
8+
file="bin/$name"
9+
if [ ! -f "$built/$name" ]; then
10+
echo "::error::the build did not produce $name"
11+
exit 1
12+
fi
13+
if [ ! -f "$file" ]; then
14+
echo "::error file=$file::missing"
15+
fail=1
16+
continue
17+
fi
18+
if ! cmp -s "$built/$name" "$file"; then
19+
echo "::error file=$file::differs from a fresh build of native/"
20+
fail=1
21+
fi
22+
mode=$(git ls-files --stage -- "$file" | cut -d' ' -f1)
23+
if [ "$mode" != "100755" ]; then
24+
echo "::error file=$file::must be committed as executable (git mode is ${mode:-untracked})"
25+
fail=1
26+
fi
27+
done
28+
if ! cmp -s "$built/SHA256SUMS" bin/SHA256SUMS; then
29+
echo "::error file=bin/SHA256SUMS::differs from the fresh build's checksums"
30+
fail=1
31+
fi
32+
33+
if [ "$fail" -ne 0 ]; then
34+
echo "bin/ does not match a build of native/, update it from this run's artifact:"
35+
echo " gh run download ${GITHUB_RUN_ID:-<run-id>} --repo ${GITHUB_REPOSITORY:-composer/zstd} --name zstd-extract-binaries --dir bin/"
36+
echo " chmod +x bin/zstd-extract-* && git add --chmod=+x bin/"
37+
exit 1
38+
fi
39+
echo "bin/ is identical to the fresh build"

‎.github/workflows/binaries.yml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: "Native binaries"
2+
3+
# bin/ must always be byte-identical to a fresh build of native/. When it is not, the job prints how to update it
4+
# from this run's artifact.
5+
6+
on:
7+
push:
8+
paths:
9+
- 'bin/**'
10+
- 'native/**'
11+
- '.github/workflows/binaries.yml'
12+
- '.github/workflows/build.yml'
13+
- '.github/scripts/compare-binaries.sh'
14+
pull_request:
15+
paths:
16+
- 'bin/**'
17+
- 'native/**'
18+
- '.github/workflows/binaries.yml'
19+
- '.github/workflows/build.yml'
20+
- '.github/scripts/compare-binaries.sh'
21+
workflow_dispatch:
22+
23+
permissions:
24+
contents: read
25+
26+
concurrency:
27+
group: ${{ github.workflow }}-${{ github.ref }}
28+
cancel-in-progress: true
29+
30+
jobs:
31+
build:
32+
uses: ./.github/workflows/build.yml
33+
34+
compare:
35+
name: "Compare with bin/"
36+
needs: build
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
40+
with:
41+
persist-credentials: false
42+
43+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
44+
with:
45+
name: zstd-extract-binaries
46+
path: ${{ runner.temp }}/built
47+
48+
- name: Compare
49+
run: .github/scripts/compare-binaries.sh "$RUNNER_TEMP/built"

‎.github/workflows/build.yml‎

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: "Build native binaries"
2+
3+
# Reusable: builds the zstd-extract binaries on each platform's native toolchain, twice to make sure the build is
4+
# deterministic, and uploads them with their checksums as the "zstd-extract-binaries" artifact.
5+
6+
on:
7+
workflow_call:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
linux:
14+
name: "Linux ${{ matrix.arch }}"
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
include:
19+
- os: ubuntu-24.04
20+
arch: x86_64
21+
- os: ubuntu-24.04-arm
22+
arch: aarch64
23+
steps:
24+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
25+
with:
26+
persist-credentials: false
27+
28+
- name: Build
29+
env:
30+
ARCH: ${{ matrix.arch }}
31+
run: |
32+
bin="native/build/zstd-extract-linux-$ARCH"
33+
native/build-linux.sh
34+
cp "$bin" "$RUNNER_TEMP/first"
35+
rm -rf native/build
36+
native/build-linux.sh
37+
cmp "$RUNNER_TEMP/first" "$bin" # the build must be reproducible
38+
file "$bin" | grep -q 'static-pie linked'
39+
readelf -hW "$bin" | grep -q 'Type: *DYN' # position independent, for ASLR
40+
"$bin" --version
41+
"$bin" tests/Fixtures/level19.tar.zst "$RUNNER_TEMP/smoke"
42+
test -L "$RUNNER_TEMP/smoke/link-to-script"
43+
44+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
45+
with:
46+
name: linux-${{ matrix.arch }}
47+
path: native/build/zstd-extract-linux-${{ matrix.arch }}
48+
if-no-files-found: error
49+
50+
darwin:
51+
name: "macOS universal"
52+
runs-on: macos-latest
53+
steps:
54+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
55+
with:
56+
persist-credentials: false
57+
58+
- name: Build
59+
run: |
60+
bin=native/build/zstd-extract-darwin
61+
make -C native darwin
62+
cp "$bin" "$RUNNER_TEMP/first"
63+
make -C native clean darwin
64+
cmp "$RUNNER_TEMP/first" "$bin" # the build must be reproducible
65+
lipo -archs "$bin" | grep -q 'x86_64 arm64'
66+
codesign --verify "$bin"
67+
"$bin" --version
68+
"$bin" tests/Fixtures/level19.tar.zst "$RUNNER_TEMP/smoke"
69+
test -L "$RUNNER_TEMP/smoke/link-to-script"
70+
71+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
72+
with:
73+
name: darwin
74+
path: native/build/zstd-extract-darwin
75+
if-no-files-found: error
76+
77+
windows:
78+
name: "Windows x86_64"
79+
runs-on: windows-latest
80+
steps:
81+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
82+
with:
83+
persist-credentials: false
84+
85+
- name: Build
86+
shell: pwsh
87+
run: |
88+
$bin = 'native\build\zstd-extract-windows-x86_64.exe'
89+
cmd /c native\build-windows.cmd
90+
if ($LASTEXITCODE -ne 0) { exit 1 }
91+
Copy-Item $bin "$env:RUNNER_TEMP\first.exe"
92+
Remove-Item -Recurse native\build
93+
cmd /c native\build-windows.cmd
94+
if ($LASTEXITCODE -ne 0) { exit 1 }
95+
# the build must be reproducible
96+
if ((Get-FileHash $bin).Hash -ne (Get-FileHash "$env:RUNNER_TEMP\first.exe").Hash) { Write-Error 'non-deterministic build'; exit 1 }
97+
& $bin --version
98+
if ($LASTEXITCODE -ne 0) { exit 1 }
99+
& $bin tests\Fixtures\level19.tar.zst "$env:RUNNER_TEMP\smoke"
100+
if ($LASTEXITCODE -ne 0) { exit 1 }
101+
if (-not (Test-Path "$env:RUNNER_TEMP\smoke\link-to-script" -PathType Leaf)) { exit 1 }
102+
103+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
104+
with:
105+
name: windows-x86_64
106+
path: native/build/zstd-extract-windows-x86_64.exe
107+
if-no-files-found: error
108+
109+
collect:
110+
name: "Collect"
111+
needs: [linux, darwin, windows]
112+
runs-on: ubuntu-latest
113+
steps:
114+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
115+
with:
116+
path: bin
117+
pattern: '{linux-*,darwin,windows-*}'
118+
merge-multiple: true
119+
120+
- name: Checksums
121+
run: |
122+
chmod +x bin/zstd-extract-*
123+
cd bin && LC_ALL=C sha256sum zstd-extract-* | tee SHA256SUMS
124+
125+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
126+
with:
127+
name: zstd-extract-binaries
128+
path: bin/
129+
if-no-files-found: error
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
tests:
16+
name: "CI (PHP ${{ matrix.php-version }}, ${{ matrix.os }})"
17+
18+
runs-on: ${{ matrix.os }}
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
php-version:
24+
- "7.2"
25+
- "7.3"
26+
- "7.4"
27+
- "8.0"
28+
- "8.1"
29+
- "8.2"
30+
- "8.3"
31+
- "8.4"
32+
- "8.5"
33+
os: [ubuntu-latest]
34+
# every extraction method must be tested; Windows runners may lack the zstd CLI or a PECL build
35+
require-methods: ["ext-zstd,bundled,zstd-cli,php"]
36+
include:
37+
- php-version: "8.4"
38+
os: ubuntu-24.04-arm
39+
require-methods: "ext-zstd,bundled,zstd-cli,php"
40+
- php-version: "7.2"
41+
os: macos-latest
42+
require-methods: "ext-zstd,bundled,zstd-cli,php"
43+
- php-version: "8.4"
44+
os: macos-latest
45+
require-methods: "ext-zstd,bundled,zstd-cli,php"
46+
- php-version: "7.2"
47+
os: windows-latest
48+
require-methods: "bundled,php"
49+
- php-version: "8.4"
50+
os: windows-latest
51+
require-methods: "bundled,php"
52+
53+
steps:
54+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
55+
with:
56+
persist-credentials: false
57+
58+
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
59+
with:
60+
php-version: "${{ matrix.php-version }}"
61+
extensions: zstd
62+
coverage: none
63+
64+
- name: Install the zstd CLI (Linux)
65+
if: runner.os == 'Linux'
66+
run: command -v zstd || sudo apt-get install -y zstd
67+
68+
- name: Install the zstd CLI (macOS)
69+
if: runner.os == 'macOS'
70+
run: command -v zstd || brew install zstd
71+
72+
# test the current C sources, not just the committed binaries
73+
- name: Build native binary (Linux)
74+
if: runner.os == 'Linux'
75+
run: |
76+
native/build-linux.sh
77+
echo "ZSTD_EXTRACT_BINARY=$PWD/native/build/zstd-extract-linux-$(uname -m)" >> "$GITHUB_ENV"
78+
79+
- name: Build native binary (macOS)
80+
if: runner.os == 'macOS'
81+
run: |
82+
make -C native darwin
83+
echo "ZSTD_EXTRACT_BINARY=$PWD/native/build/zstd-extract-darwin" >> "$GITHUB_ENV"
84+
85+
- name: Build native binary (Windows)
86+
if: runner.os == 'Windows'
87+
shell: pwsh
88+
run: |
89+
cmd /c native\build-windows.cmd
90+
if ($LASTEXITCODE -ne 0) { exit 1 }
91+
"ZSTD_EXTRACT_BINARY=$PWD\native\build\zstd-extract-windows-x86_64.exe" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
92+
93+
- name: Remove PHPStan on PHP < 7.4
94+
if: matrix.php-version == '7.2' || matrix.php-version == '7.3'
95+
run: composer remove --dev --no-update phpstan/phpstan phpstan/phpstan-strict-rules phpstan/phpstan-deprecation-rules
96+
97+
- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
98+
with:
99+
dependency-versions: highest
100+
101+
- name: Run tests
102+
env:
103+
ZSTD_TEST_REQUIRE_METHODS: ${{ matrix.require-methods }}
104+
run: vendor/bin/phpunit

0 commit comments

Comments
 (0)