Skip to content

Commit d3335fc

Browse files
Merge pull request #14 from xphp-lang/ci/build-phar
ci: build PHAR + SHA256 sum on every v* tag
2 parents cd45ad0 + 3682bb9 commit d3335fc

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
# Required to create the GitHub Release and upload assets via
8+
# softprops/action-gh-release.
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
phar:
14+
name: Build + publish PHAR
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Setup PHP 8.4
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.4'
23+
extensions: dom, json, mbstring, tokenizer, phar
24+
coverage: none
25+
tools: composer:v2
26+
27+
- name: Build PHAR
28+
# `make build/phar` strips dev dependencies, downloads
29+
# box.phar lazily into var/, compiles dist/xphp.phar, then
30+
# restores the dev install. See Makefile for the rationale.
31+
run: make build/phar
32+
33+
- name: Smoke-test the PHAR
34+
# If the PHAR is broken (missing autoload, bad shebang,
35+
# excluded a runtime dep), `list` exits non-zero and the
36+
# release fails BEFORE the asset is uploaded.
37+
run: php dist/xphp.phar list
38+
39+
- name: Compute SHA256 sum
40+
# `sha256sum` outputs `<hex> <filename>`; running it from
41+
# the dist/ directory keeps the filename relative so users
42+
# can `sha256sum -c xphp.phar.sha256sum` after downloading
43+
# both files into the same directory.
44+
working-directory: dist
45+
run: sha256sum xphp.phar > xphp.phar.sha256sum
46+
47+
- name: Attach assets to GitHub Release
48+
# softprops/action-gh-release creates the release matched by
49+
# tag name if it doesn't already exist, then appends the
50+
# listed files as assets. Release body stays
51+
# auto-generated unless `body:` / `body_path:` is set later.
52+
uses: softprops/action-gh-release@v2
53+
with:
54+
files: |
55+
dist/xphp.phar
56+
dist/xphp.phar.sha256sum
57+
fail_on_unmatched_files: true

‎Makefile‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,34 @@ test/unit:
1717
# repo is stable enough that no new test gaps are expected.
1818
test/mutation:
1919
php vendor/bin/infection --show-mutations=max --threads=max --min-covered-msi=95
20+
21+
# Humbug Box is the standard tool for compiling a Composer-managed
22+
# PHP project into a single self-contained PHAR. Pinned to a known-
23+
# good release (Box 4.6.6 supports PHP 8.4) so a new Box version
24+
# can't silently break the build. Bump after validating locally.
25+
BOX_VERSION := 4.6.6
26+
BOX_PHAR := var/box.phar
27+
28+
$(BOX_PHAR):
29+
@mkdir -p $(dir $(BOX_PHAR))
30+
@echo "==> Downloading box.phar $(BOX_VERSION)"
31+
@curl -fsSL -o $@ \
32+
https://github.com/box-project/box/releases/download/$(BOX_VERSION)/box.phar
33+
@chmod +x $@
34+
35+
.PHONY: build/phar
36+
# Builds dist/xphp.phar -- the release artifact attached to every
37+
# `v*` tag by .github/workflows/release.yml. Box reads box.json at
38+
# the repo root and auto-discovers what to include from
39+
# composer.json.
40+
#
41+
# `composer install` runs twice on purpose: once with --no-dev to
42+
# strip phpunit/infection/etc. from the PHAR (smaller artifact, no
43+
# test machinery shipped to users), then once more in dev mode so
44+
# the next `make test/unit` keeps working without a separate
45+
# install step.
46+
build/phar: $(BOX_PHAR)
47+
composer install --no-dev --classmap-authoritative --quiet --no-interaction
48+
php -d phar.readonly=0 $(BOX_PHAR) compile --no-interaction
49+
composer install --quiet --no-interaction
50+
@echo "==> Built $$(ls -lh dist/xphp.phar | awk '{print $$5, $$9}')"

‎box.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "vendor/humbug/box/res/schema.json",
3+
"main": "bin/xphp",
4+
"output": "dist/xphp.phar",
5+
"compression": "GZ",
6+
"banner": "xphp -- generic-aware PHP transpiler.\nhttps://github.com/xphp-lang/xphp"
7+
}

0 commit comments

Comments
 (0)