Skip to content

Build packages

Build packages #4767

name: Build packages
on:
pull_request:
paths:
- 'base-*/**'
- 'core-*/**'
- 'extra-*/**'
issue_comment:
types: [created]
workflow_dispatch:
inputs:
packages:
description: 'Packages to build'
required: true
concurrency:
group: ${{github.event.pull_request.number || github.event.issue.number || github.event.inputs.packages}}
cancel-in-progress: true
permissions:
issues: write
pull-requests: write
jobs:
get-packages:
if: ${{((github.event.pull_request && startsWith(github.event.pull_request.title, '[ci]')) || (github.event.comment.body == '/build' && github.event.issue.pull_request) || startsWith(github.event.comment.body, '/build ')) || github.event.inputs.packages}}
runs-on: ubuntu-latest
steps:
- name: Add reaction to invocation comment
uses: peter-evans/create-or-update-comment@v3
if: ${{github.event.comment}}
with:
comment-id: ${{github.event.comment.id}}
reactions: rocket
- name: Create comment
uses: peter-evans/create-or-update-comment@v3
id: create-comment
if: ${{github.event.comment}}
with:
issue-number: ${{github.event.issue.number}}
body: |
🥰 Packages are building at ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}.
- uses: actions/checkout@v4
if: ${{github.event.pull_request}}
with:
ref: 'stable'
- uses: actions/checkout@v4
if: ${{github.event.pull_request || github.event.comment.body == '/build'}}
with:
fetch-depth: 0
- name: Checkout pull request
if: ${{github.event.pull_request || github.event.comment.body == '/build'}}
env:
PR_NUMBER: ${{github.event.pull_request.number || github.event.issue.number}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
gh pr checkout $PR_NUMBER
- name: Get packages to build from repository
uses: actions/github-script@v7
id: get-packages-from-repo
if: ${{github.event.pull_request || github.event.comment.body == '/build'}}
with:
script: |
let args = "";
const options = {};
options.listeners = {
stdout: (data) => {
args += data.toString();
}
};
await exec.exec('git', ['merge-base', 'origin/stable', 'HEAD'], options);
const parent = args.split('\n');
args = "";
await exec.exec('git', ['diff', '--name-only', parent[0], 'HEAD', '*/spec'], options);
const regex = /.*\/(.*)\/.*/;
const packages = args.split('\n').map(arg => regex.exec(arg)).filter(arg => Array.isArray(arg)).map(arg => arg[1]);
if (!Array.isArray(packages) || packages.length == 0) throw "No packages to build in the repository!";
return packages;
- name: Get packages to build from command line
uses: actions/github-script@v7
id: get-packages-from-command-line
if: ${{startsWith(github.event.comment.body, '/build ')}}
with:
script: |
const args = context.payload.comment.body;
const regex = /\/build ([a-z\d\/\.\-\+ ]+)/;
const isMatched = args.match(regex);
if (!isMatched) throw "No packages found in the command!";
const packages = args.split('/build ')[1].split(' ');
return packages;
- name: Get packages to build from input
uses: actions/github-script@v7
id: get-packages-from-input
if: ${{github.event.inputs.packages}}
with:
script: |
const args = context.payload.inputs.packages;
const regex = /([a-z\d\/\.\-\+ ]+)/;
const isMatched = args.match(regex);
if (!isMatched) throw "No packages found in the command!";
const packages = args.split(' ');
return packages;
- name: Update comment
uses: peter-evans/create-or-update-comment@v3
if: ${{failure() && github.event.comment}}
with:
comment-id: ${{steps.create-comment.outputs.comment-id}}
body: |
❌ Nothing to do!
outputs:
matrix: ${{steps.get-packages-from-repo.outputs.result || steps.get-packages-from-command-line.outputs.result || steps.get-packages-from-input.outputs.result}}
comment-id: ${{steps.create-comment.outputs.comment-id}}
build:
needs: get-packages
runs-on: ubuntu-latest
container: ghcr.io/aosc-dev/aosc-os-buildkit-daily:latest
strategy:
matrix:
package: ${{fromJson(needs.get-packages.outputs.matrix)}}
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Configure the container
run: |
mkdir -p /var/lib/acbs
ln -s $GITHUB_WORKSPACE /var/lib/acbs/repo
sed -i 's/Null Packager <[email protected]>/GitHub Actions <[email protected]>/' /etc/autobuild/ab3cfg.sh
apt-get update && yes | apt-get -yf full-upgrade && apt-get -y autoremove
- name: Install GitHub CLI
if: ${{github.event.pull_request || github.event.issue.pull_request}}
run: |
yes | apt-get -yf install gh
- name: Checkout pull request
if: ${{github.event.pull_request || github.event.issue.pull_request}}
env:
PR_NUMBER: ${{github.event.pull_request.number || github.event.issue.number}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
gh pr checkout $PR_NUMBER
- name: Build the package
shell: 'script -eqc "bash --noprofile --norc -eo pipefail {0}"'
env:
PACKAGE: ${{matrix.package}}
TERM: xterm-new
CARGO_TERM_COLOR: always
run: acbs-build "$PACKAGE"
- name: Upload the package
uses: actions/upload-artifact@v4
with:
name: debs_${{matrix.package}}
path: /debs
if-no-files-found: error
- name: Update comment when succeed
uses: peter-evans/create-or-update-comment@v3
if: ${{!github.event.pull_request}}
with:
comment-id: ${{needs.get-packages.outputs.comment-id}}
body: |
✅ Building `${{matrix.package}}` ends with status **${{job.status}}**.
- name: Update comment when not succeed
uses: peter-evans/create-or-update-comment@v3
if: ${{!success() && !github.event.pull_request}}
with:
comment-id: ${{needs.get-packages.outputs.comment-id}}
body: |
❌ Building `${{matrix.package}}` ends with status **${{job.status}}**.