Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build-phar-on-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Build PHAR on Release

on:
release:
types: [created]

jobs:
build-phar:
uses: ./.github/workflows/build-phar.yml
with:
tag_name: ${{ github.event.release.tag_name }}
32 changes: 24 additions & 8 deletions .github/workflows/build-phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ name: Build PHAR
on:
# Manual trigger
workflow_dispatch:
inputs:
tag_name:
description: Git tag to attach PHAR to, e.g. v0.1.0 (leave empty for artifact only)
required: false
type: string

# Trigger when a release is created
release:
types: [created]
# Called by release-please workflow after release creation
# (release events from GITHUB_TOKEN don't trigger other workflows)
workflow_call:
inputs:
tag_name:
description: Git tag to attach PHAR to (e.g., v0.1.0)
required: true
type: string

permissions:
contents: write
Expand All @@ -19,6 +29,9 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag_name || github.ref }}
fetch-tags: true

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -44,28 +57,31 @@ jobs:

- name: Build PHAR
run: php build.php
env:
BUILD_VERSION: ${{ inputs.tag_name }}

- name: Test PHAR
run: |
./build/oce-import-codes.phar --version
./build/oce-import-codes.phar --help

- name: Create versioned PHAR
if: github.event_name == 'release'
if: inputs.tag_name
run: |
VERSION=${{ github.event.release.tag_name }}
VERSION=${{ inputs.tag_name }}
cp build/oce-import-codes.phar build/oce-import-codes-${VERSION}.phar

- name: Upload PHAR to release
if: github.event_name == 'release'
if: inputs.tag_name
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.tag_name }}
files: |
build/oce-import-codes.phar
build/oce-import-codes-${{ github.event.release.tag_name }}.phar
build/oce-import-codes-${{ inputs.tag_name }}.phar

- name: Upload PHAR artifact (manual trigger)
if: github.event_name == 'workflow_dispatch'
if: ${{ !inputs.tag_name }}
uses: actions/upload-artifact@v4
with:
name: oce-import-codes-phar
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ permissions:
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -60,3 +63,13 @@ jobs:
TAG_NAME="${{ steps.release.outputs.tag_name }}"
git tag -a -f -m "Release ${TAG_NAME}" "${TAG_NAME}" "${TAG_NAME}^{commit}"
git push -f origin "${TAG_NAME}"

# Build and attach PHAR to release
# This is called directly because release events from GITHUB_TOKEN
# don't trigger other workflows (GitHub security feature)
build-phar:
needs: release-please
if: ${{ needs.release-please.outputs.release_created == 'true' }}
uses: ./.github/workflows/build-phar.yml
with:
tag_name: ${{ needs.release-please.outputs.tag_name }}
10 changes: 8 additions & 2 deletions build.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
$buildDir = __DIR__ . '/build';
$pharFile = $buildDir . '/oce-import-codes.phar';

echo "Building oce-import-codes.phar...\n";
// Determine version: BUILD_VERSION env var > git describe > fallback
$version = getenv('BUILD_VERSION') ?: null;
if (!$version) {
$version = trim((string) shell_exec('git describe --tags 2>/dev/null')) ?: 'dev';
}

echo "Building oce-import-codes.phar (version: $version)...\n";

// Create build directory
if (!is_dir($buildDir)) {
Expand All @@ -45,7 +51,7 @@
// Set metadata
$phar->setMetadata([
'name' => 'oce-import-codes',
'version' => '1.0.0',
'version' => $version,
'created' => date('Y-m-d H:i:s')
]);

Expand Down