GitHub Actions: Bikeshedding #61
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
tags: | |
- '**' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.event.pull_request.number || github.sha }} | |
cancel-in-progress: true | |
permissions: {} | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
phar: | |
runs-on: ubuntu-24.04 | |
outputs: | |
php-version: ${{ steps.setup-php.outputs.php-version }} | |
steps: | |
- uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
- uses: shivammathur/setup-php@v2 | |
id: setup-php | |
with: | |
php-version: '8.4' | |
coverage: none | |
tools: box:4 | |
- uses: ramsey/composer-install@v3 | |
with: | |
composer-options: --no-dev --prefer-dist | |
- run: box compile | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: composer-semver.phar | |
path: phar/composer-semver | |
if-no-files-found: error | |
build: | |
needs: phar | |
strategy: | |
matrix: | |
runs-on: | |
- ubuntu-24.04-arm | |
- ubuntu-24.04 | |
- macos-15 | |
- macos-15-intel | |
runs-on: ${{ matrix.runs-on }} | |
steps: | |
- uses: actions/checkout@v5 | |
with: | |
sparse-checkout: | | |
.github/actions/set-envs | |
craft.yml | |
sparse-checkout-cone-mode: false | |
- uses: ./.github/actions/set-envs | |
- run: echo SPC_OS=linux >> $GITHUB_ENV | |
if: runner.os == 'Linux' | |
- run: echo SPC_OS=macos >> $GITHUB_ENV | |
if: runner.os == 'macOS' | |
- run: | | |
echo "::error title=Unable to determine SPC_OS::Unexpected runner.os '${RUNNER_OS}'" | |
exit 1 | |
if: env.SPC_OS == '' | |
env: | |
RUNNER_OS: ${{ runner.os }} | |
- run: echo SPC_ARCH=aarch64 >> $GITHUB_ENV | |
if: runner.arch == 'ARM64' | |
- run: echo SPC_ARCH=x86_64 >> $GITHUB_ENV | |
if: runner.arch == 'X64' | |
- run: | | |
echo "::error title=Unable to determine SPC_ARCH::Unexpected runner.arch '${RUNNER_ARCH}'" | |
exit 1 | |
if: env.SPC_ARCH == '' | |
env: | |
RUNNER_ARCH: ${{ runner.arch }} | |
- name: Install spc | |
run: | | |
gh release download --repo crazywhalecc/static-php-cli --pattern "${PATTERN}" --output spc.tar.gz && \ | |
mkdir -p /tmp/spc && \ | |
tar -xvf spc.tar.gz --directory /tmp/spc && \ | |
echo "/tmp/spc" >> "$GITHUB_PATH" | |
env: | |
PATTERN: spc-${{ env.SPC_OS }}-${{ env.SPC_ARCH }}.tar.gz | |
GH_TOKEN: ${{ github.token }} | |
- uses: actions/download-artifact@v5 | |
with: | |
name: composer-semver.phar | |
path: phar | |
- name: Restore cached micro.sfx | |
id: restore-micro-sfx | |
uses: actions/cache/restore@v4 | |
with: | |
path: buildroot/bin/micro.sfx | |
key: micro-sfx-${{ runner.os }}-${{ runner.arch }}-${{ needs.phar.outputs.php-version }}-${{ hashFiles('craft.yml') }} | |
- name: Build micro.sfx | |
if: steps.restore-micro-sfx.outputs.cache-hit != 'true' | |
run: spc craft | |
env: | |
GITHUB_TOKEN: ${{ github.token }} # Not a typo. | |
- name: Cache micro.sfx | |
id: cache-micro-sfx | |
if: steps.restore-micro-sfx.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: buildroot/bin/micro.sfx | |
key: ${{ steps.restore-micro-sfx.outputs.cache-primary-key }} | |
- run: mkdir -p out | |
- run: spc micro:combine phar/composer-semver --output out/composer-semver | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: composer-semver_${{ env.OS }}_${{ env.ARCH }} | |
path: out/composer-semver | |
if-no-files-found: error | |
nfpm: | |
needs: build | |
runs-on: ubuntu-24.04-arm | |
steps: | |
- name: Set VERSION environment variable | |
run: echo VERSION="${TAGISH#v}" >> $GITHUB_ENV | |
env: | |
TAGISH: ${{ github.ref_type == 'tag' && github.ref_name || format('v0.0.0-{0}+{1}', github.run_number, github.sha) }} | |
- run: echo "${VERSION}" | |
- name: Download nfpm | |
run: gh release download --repo goreleaser/nfpm --pattern 'nfpm_*_arm64.deb' --output nfpm.deb | |
env: | |
GH_TOKEN: ${{ github.token }} | |
- name: Install nfpm | |
run: sudo dpkg -i nfpm.deb | |
- uses: actions/checkout@v5 | |
with: | |
sparse-checkout: | | |
nfpm.yaml | |
README.md | |
LICENSE | |
sparse-checkout-cone-mode: false | |
- uses: actions/download-artifact@v5 | |
with: | |
pattern: composer-semver_Linux_* | |
path: dist | |
- run: mkdir -p deb | |
- name: Creates packages | |
run: | | |
for arch in ${ARCHS}; do | |
echo "::group::==> ${arch}" | |
DIST_DIR="dist/composer-semver_Linux_${arch}" \ | |
ARCH="${arch}" nfpm package --packager deb --target "deb/composer-semver_Linux_${arch}.deb" | |
echo "::endgroup::" | |
done | |
env: | |
DIST_DIR: dist | |
ARCHS: "arm64 amd64" | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: deb | |
path: deb/*.deb | |
if-no-files-found: error | |
test-linux: | |
needs: nfpm | |
strategy: | |
matrix: | |
runs-on: | |
- ubuntu-24.04-arm | |
- ubuntu-24.04 | |
runs-on: ${{ matrix.runs-on }} | |
env: | |
GOFLAGS: '-mod=mod' | |
steps: | |
- uses: actions/checkout@v5 | |
- uses: ./.github/actions/set-envs | |
- uses: actions/download-artifact@v5 | |
with: | |
name: deb | |
path: deb | |
- run: sudo dpkg -i "deb/composer-semver_Linux_${ARCH}.deb" | |
- uses: actions/setup-go@v6 | |
with: | |
go-version-file: 'go.mod' | |
- name: Print composer-semver binary path | |
run: go test -count=1 -v ./internal | |
- run: go test -count=1 ./... | |
test-darwin: | |
needs: build | |
strategy: | |
matrix: | |
runs-on: | |
- macos-15 | |
- macos-15-intel | |
runs-on: ${{ matrix.runs-on }} | |
env: | |
GOFLAGS: '-mod=mod' | |
steps: | |
- uses: actions/checkout@v5 | |
- uses: ./.github/actions/set-envs | |
- uses: actions/download-artifact@v5 | |
with: | |
name: composer-semver_Darwin_${{ env.ARCH }} | |
path: out | |
- name: Grant composer-semver binary execute permission | |
run: chmod +x out/composer-semver | |
- name: Add composer-semver binary into PATH | |
run: echo "${WORKSPACE}/out" >> "$GITHUB_PATH" | |
env: | |
WORKSPACE: ${{ github.workspace }} | |
- uses: actions/setup-go@v6 | |
with: | |
go-version-file: 'go.mod' | |
- name: Print composer-semver binary path | |
run: go test -count=1 -v ./internal | |
- run: go test -count=1 ./... | |
dispatch: | |
if: github.event_name == 'push' && github.ref_type == 'tag' | |
needs: | |
- test-linux | |
- test-darwin | |
permissions: | |
actions: write | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Dispatch Release Workflow | |
run: | | |
gh workflow run release.yml \ | |
--repo "${REPO}" \ | |
--ref "${REF}" \ | |
-f version="${VERSION}" \ | |
-f run_id="${RUN_ID}" | |
env: | |
REPO: ${{ github.repository }} | |
REF: ${{ github.ref }} | |
VERSION: ${{ github.ref_name }} | |
RUN_ID: ${{ github.run_id }} | |
GH_TOKEN: ${{ github.token }} |