Skip to content

ci: use actions/cache for restore/save cache, gh for deleting cache #138

ci: use actions/cache for restore/save cache, gh for deleting cache

ci: use actions/cache for restore/save cache, gh for deleting cache #138

Workflow file for this run

name: CI
on:
push:
pull_request_target:
permissions:
actions: write
contents: read
packages: write
env:
DOCKER_DRIVER: overlay2
FAST_MODE: false
jobs:
build-image:
name: Build Image
runs-on: ubuntu-22.04
outputs:
image-tag: ${{ steps.prepare.outputs.image-tag }}
repo-name: ${{ steps.prepare.outputs.repo-name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Prepare
id: prepare
run: |
BRANCH_NAME=$(echo "${GITHUB_REF##*/}" | tr '[:upper:]' '[:lower:]')
REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "image-tag=${BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "repo-name=${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-name }}/dashcore-ci-runner:${{ steps.prepare.outputs.image-tag }}
ghcr.io/${{ steps.prepare.outputs.repo-name }}/dashcore-ci-runner:latest
cache-from: type=registry,ref=ghcr.io/${{ steps.prepare.outputs.repo-name }}/dashcore-ci-runner:latest
cache-to: type=inline
build-depends:
name: ${{ matrix.depends_name }}
needs: build-image
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include:
- depends_name: arm-linux-gnueabihf
host: arm-linux-gnueabihf
dep_opts: ""
- depends_name: x86_64-pc-linux-gnu_debug
host: x86_64-pc-linux-gnu
dep_opts: "DEBUG=1"
- depends_name: x86_64-pc-linux-gnu_multiprocess
host: x86_64-pc-linux-gnu
dep_opts: "DEBUG=1 MULTIPROCESS=1 CC=clang-18 CXX='clang++-18 -stdlib=libc++'"
- depends_name: x86_64-pc-linux-gnu_nowallet
host: x86_64-pc-linux-gnu
dep_opts: "NO_WALLET=1"
container:
image: ghcr.io/${{ needs.build-image.outputs.repo-name }}/dashcore-ci-runner:${{ needs.build-image.outputs.image-tag }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Cache depends sources
uses: actions/cache@v4
with:
path: |
depends/sources
key: depends-sources-${{ hashFiles('depends/packages/*') }}
restore-keys: |
depends-sources-
- name: Restore depends cache
id: cache-restore-deps
uses: actions/cache/restore@v4
with:
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}
- name: Build depends
run: env HOST=${{ matrix.host }} ${{ matrix.dep_opts }} make -j$(nproc) -C depends
- name: Delete depends cache
id: cache-delete-deps
if: ${{ steps.cache-restore-deps.outputs.cache-hit }}
continue-on-error: true
run: |
git config --global --add safe.directory "$(pwd)"
gh cache delete "${{ steps.cache-restore-deps.outputs.cache-primary-key }}"
env:
GH_TOKEN: ${{ github.token }}
- name: Save depends cache
id: cache-save-deps
uses: actions/cache/save@v4
with:
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ steps.cache-restore-deps.outputs.cache-primary-key }}
build:
name: ${{ matrix.build_target }}
needs: [build-image, build-depends]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include:
- build_target: arm-linux
depends_name: arm-linux-gnueabihf
host: arm-linux-gnueabihf
- build_target: linux64
depends_name: x86_64-pc-linux-gnu_debug
host: x86_64-pc-linux-gnu
- build_target: linux64_cxx20
depends_name: x86_64-pc-linux-gnu_debug
host: x86_64-pc-linux-gnu
- build_target: linux64_fuzz
depends_name: x86_64-pc-linux-gnu_debug
host: x86_64-pc-linux-gnu
- build_target: linux64_multiprocess
depends_name: x86_64-pc-linux-gnu_multiprocess
host: x86_64-pc-linux-gnu
- build_target: linux64_nowallet
depends_name: x86_64-pc-linux-gnu_nowallet
host: x86_64-pc-linux-gnu
- build_target: linux64_sqlite
depends_name: x86_64-pc-linux-gnu_debug
host: x86_64-pc-linux-gnu
- build_target: linux64_tsan
depends_name: x86_64-pc-linux-gnu_multiprocess
host: x86_64-pc-linux-gnu
- build_target: linux64_ubsan
depends_name: x86_64-pc-linux-gnu_debug
host: x86_64-pc-linux-gnu
container:
image: ghcr.io/${{ needs.build-image.outputs.repo-name }}/dashcore-ci-runner:${{ needs.build-image.outputs.image-tag }}
options: --user root
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Restore depends cache
uses: actions/cache/restore@v4
with:
path: |
depends/built
depends/${{ matrix.host }}
key: ${{ runner.os }}-depends-${{ matrix.depends_name }}-${{ hashFiles('depends/packages/*') }}
- name: Determine PR Base SHA
id: vars
run: |
echo "PR_BASE_SHA=${{ github.event.pull_request.base.sha || '' }}" >> $GITHUB_OUTPUT
- name: CCache
uses: actions/cache@v4
with:
path: |
/cache
key: ${{ runner.os }}-${{ matrix.build_target }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.build_target }}-${{ github.sha }}
${{ runner.os }}-${{ matrix.build_target }}-${{ steps.vars.outputs.PR_BASE_SHA }}
${{ runner.os }}-${{ matrix.build_target }}
- name: Build source and run tests
run: |
git config --global --add safe.directory "$PWD"
CCACHE_SIZE="400M"
CACHE_DIR="/cache"
mkdir /output
BASE_OUTDIR="/output"
BUILD_TARGET="${{ matrix.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-${{ matrix.build_target }}
path: |
/output