Skip to content

Build for Linux

Build for Linux #484

Workflow file for this run

name: Build for Linux
on:
push:
branches:
- main
# PR branches that alter the build process should be prefixed with `build/`, so
# that this workflow runs.
- 'build/**'
schedule:
# Run this workflow every 8 hours to repackage the pre-built Drupal CMS site
# with the latest dependencies.
- cron: 0 */8 * * *
workflow_dispatch:
env:
# The extensions and libraries needed to build PHP. These need to be variables so we can
# use them to generate a cache key.
# @see https://static-php.dev/en/guide/cli-generator.html
PHP_EXTENSIONS: bz2,ctype,curl,dom,filter,gd,iconv,mbstring,opcache,openssl,pcntl,pdo,pdo_sqlite,phar,posix,session,simplexml,sodium,sqlite3,tokenizer,xml,xmlwriter,yaml,zip,zlib
PHP_VERSION: 8.3
# Don't publish by default. This is overridden for the release branch, below.
PUBLISH: never
# On Linux, we need to build separate versions for x64 and arm64. Their build process is
# identical; the only difference is what kind of machine they are targeting. So it's all
# done as a single job, but run as a matrix.
jobs:
app:
name: App on ${{ matrix.runner }}
strategy:
matrix:
runner:
- ubuntu-latest # x64
- ubuntu-22.04-arm # arm64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check out latest tag
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
run: |
LATEST_TAG=$(git describe --tags --abbrev=0)
git checkout $LATEST_TAG
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
# Install PHP with the tools needed to build the interpreter, if necessary.
php-version: latest
tools: pecl, composer
extensions: curl, openssl, mbstring, tokenizer
ini-values: memory_limit=-1
# Cache the built binary so we can skip the build steps if there is a cache hit.
- name: Generate cache key
shell: bash
run: |
CACHE_KEY=${{ runner.os }}-${{ runner.arch }}-$PHP_VERSION--$(echo $PHP_EXTENSIONS | tr ',' '-')
echo "CACHE_KEY=${CACHE_KEY}" >> "$GITHUB_ENV"
- id: cache-php
name: Cache PHP interpreter
uses: actions/cache@v4
with:
path: build/buildroot/bin
key: php-${{ env.CACHE_KEY }}
- if: steps.cache-php.outputs.cache-hit != 'true'
name: Install dependencies and build PHP
run: |
composer install
composer exec spc -- doctor
composer exec spc -- download --with-php=${{ env.PHP_VERSION }} --for-extensions=${{ env.PHP_EXTENSIONS }} --prefer-pre-built
composer exec spc -- build ${{ env.PHP_EXTENSIONS }} --build-cli --with-libs=freetype,libavif,libjpeg,libwebp --debug
env:
# Allows static-php-cli to download its many dependencies more smoothly.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: build
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: latest
- name: Cache dependencies
id: cache
uses: actions/cache@v4
with:
path: node_modules
key: npm-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install
# If we're on a PR branch, we don't want Electron Builder to publish the app.
- name: Enable publishing for release branch
if: github.ref_name == 'main'
run: |
# Configure Electron Builder to publish.
echo "PUBLISH=onTagOrDraft" >> $GITHUB_ENV
# Electron Builder needs a token to publish releases.
echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Make application
run: |
composer run assets --working-dir=build
cp -f ./build/buildroot/bin/php ./bin
chmod +x ./bin/php
npx electron-vite build
npx electron-builder --publish=${{ env.PUBLISH }}
# For manual testing, upload the final artifact if we're not in a release branch.
- name: Upload distributable
if: ${{ env.PUBLISH == 'never' }}
uses: actions/upload-artifact@v4
with:
name: app-${{ runner.arch }}
path: dist/*.AppImage
retention-days: 7
- name: Update prebuilt Drupal code base
if: ${{ env.LATEST_TAG }}
uses: softprops/action-gh-release@v2
with:
files: |
dist/Drupal_CMS-Linux-arm64.AppImage
dist/Drupal_CMS-Linux-x86_64.AppImage
dist/latest-linux.yml
dist/latest-linux-arm64.yml
tag_name: ${{ env.LATEST_TAG }}