Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: refactor GitHub Actions CI to use reusable workflows, respect DEP_OPTS, build multiprocess depends with Clang #6400

Merged
merged 10 commits into from
Feb 12, 2025
54 changes: 54 additions & 0 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build container

on:
workflow_call:
outputs:
path:
description: "Path to built container"
value: ghcr.io/${{ jobs.build.outputs.repo }}/dashcore-ci-runner:${{ jobs.build.outputs.tag }}

env:
DOCKER_DRIVER: overlay2

jobs:
build:
name: Build container
runs-on: ubuntu-22.04
outputs:
tag: ${{ steps.prepare.outputs.tag }}
repo: ${{ steps.prepare.outputs.repo }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Prepare variables
id: prepare
run: |
BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '[:upper:]' '[:lower:]')
REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "tag=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "repo=${REPO_NAME}" >> $GITHUB_OUTPUT

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./contrib/containers/ci
file: ./contrib/containers/ci/Dockerfile
push: true
tags: |
ghcr.io/${{ steps.prepare.outputs.repo }}/dashcore-ci-runner:${{ steps.prepare.outputs.tag }}
ghcr.io/${{ steps.prepare.outputs.repo }}/dashcore-ci-runner:latest
cache-from: type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo }}/dashcore-ci-runner:latest
cache-to: type=inline
79 changes: 79 additions & 0 deletions .github/workflows/build-depends.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Build depends

on:
workflow_call:
inputs:
build-target:
description: "Target name as defined by matrix.sh"
required: true
type: string
container-path:
description: "Path to built container at registry"
required: true
type: string
outputs:
key:
description: "Key needed for restoring depends cache"
value: ${{ jobs.build-depends.outputs.key }}

jobs:
build-depends:
name: Build depends
runs-on: ubuntu-22.04
outputs:
key: ${{ steps.restore.outputs.cache-primary-key }}
container:
image: ${{ inputs.container-path }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Initial setup
id: setup
run: |
BUILD_TARGET="${{ inputs.build-target }}"
source ./ci/dash/matrix.sh
echo "DEP_OPTS=${DEP_OPTS}" >> "${GITHUB_OUTPUT}"
echo "HOST=${HOST}" >> "${GITHUB_OUTPUT}"
DEP_HASH="$(echo -n "${BUILD_TARGET}" "${DEP_OPTS}" "${HOST}" | sha256sum | head -c 64)"
echo "\"${BUILD_TARGET}\" has HOST=\"${HOST}\" and DEP_OPTS=\"${DEP_OPTS}\" with hash \"${DEP_HASH}\""
echo "DEP_HASH=${DEP_HASH}" >> "${GITHUB_OUTPUT}"

shell: bash

- name: Cache depends sources
uses: actions/cache@v4
with:
path: |
depends/sources
key: depends-sources-${{ hashFiles('depends/packages/*') }}
restore-keys: |
depends-sources-${{ hashFiles('depends/packages/*') }}
depends-sources-

- name: Restore cached depends
uses: actions/cache/restore@v4
id: restore
with:
path: |
depends/built
depends/${{ steps.setup.outputs.HOST }}
key: ${{ runner.os }}-depends-${{ inputs.build-target }}-${{ steps.setup.outputs.DEP_HASH }}-${{ hashFiles('depends/packages/*') }}
restore-keys: |
${{ runner.os }}-depends-${{ inputs.build-target }}-${{ hashFiles('depends/packages/*') }}
${{ runner.os }}-depends-${{ inputs.build-target }}

- name: Build depends
run: env ${{ steps.setup.outputs.DEP_OPTS }} HOST=${{ steps.setup.outputs.HOST }} make -j$(nproc) -C depends

- name: Save depends cache
uses: actions/cache/save@v4
if: steps.restore.outputs.cache-hit != 'true'
with:
path: |
depends/built
depends/${{ steps.setup.outputs.HOST }}
key: ${{ steps.restore.outputs.cache-primary-key }}
84 changes: 84 additions & 0 deletions .github/workflows/build-src.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build source

on:
workflow_call:
inputs:
build-target:
description: "Target name as defined by inputs.sh"
required: true
type: string
container-path:
description: "Path to built container at registry"
required: true
type: string
depends-key:
description: "Key needed to access cached depends"
required: true
type: string

jobs:
build-src:
name: Build source
runs-on: ubuntu-22.04
container:
image: ${{ inputs.container-path }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Initial setup
id: setup
run: |
git config --global --add advice.detachedHead false
git config --global --add safe.directory "$PWD"
GIT_HEAD="$(git rev-parse HEAD)"
git checkout develop
git checkout "${GIT_HEAD}"
BUILD_TARGET="${{ inputs.build-target }}"
source ./ci/dash/matrix.sh
echo "HOST=${HOST}" >> $GITHUB_OUTPUT
echo "PR_BASE_SHA=${{ github.event.pull_request.base.sha || '' }}" >> $GITHUB_OUTPUT
shell: bash

- name: Restore depends cache
uses: actions/cache/restore@v4
with:
path: |
depends/built
depends/${{ steps.setup.outputs.HOST }}
key: ${{ inputs.depends-key }}
fail-on-cache-miss: true

- name: Manage ccache
uses: actions/cache@v4
with:
path: |
/cache
key: ${{ runner.os }}-${{ inputs.build-target }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ inputs.build-target }}-${{ github.sha }}
${{ runner.os }}-${{ inputs.build-target }}-${{ steps.setup.outputs.HOST }}
${{ runner.os }}-${{ inputs.build-target }}

- name: Build source and run unit tests
run: |
CCACHE_SIZE="400M"
CACHE_DIR="/cache"
mkdir /output
BASE_OUTDIR="/output"
BUILD_TARGET="${{ inputs.build-target }}"
source ./ci/dash/matrix.sh
./ci/dash/build_src.sh
./ci/dash/test_unittests.sh
shell: bash

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts-${{ inputs.build-target }}
path: |
/output
Loading
Loading