Skip to content

Commit

Permalink
[CI] Backport of the cached-builds check
Browse files Browse the repository at this point in the history
  • Loading branch information
jstourac committed Jul 19, 2024
1 parent 5eaf21b commit 575f9bf
Show file tree
Hide file tree
Showing 11 changed files with 1,022 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/build-notebooks-TEMPLATE.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# inspired by
# https://github.com/thesuperzapper/kubeflow/blob/master/.github/workflows/example_notebook_servers_publish_TEMPLATE.yaml
---
name: Build & Publish Notebook Servers (TEMPLATE)

Check failure on line 4 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

4:5 [indentation] wrong indentation: expected 0 but found 4
"on":
workflow_call:
inputs:
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
# https://docs.github.com/en/actions/learn-github-actions/contexts
target:
required: true
description: "make target to build"
type: string
github:
required: true
description: "top workflow's `github`"
type: string

Check failure on line 18 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

18:1 [trailing-spaces] trailing spaces
jobs:
build:
runs-on: ubuntu-latest
env:
# GitHub image registry used for storing $(CONTAINER_ENGINE)'s cache
CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache"

Check failure on line 25 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

25:1 [trailing-spaces] trailing spaces
steps:

Check failure on line 27 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

27:1 [trailing-spaces] trailing spaces
- uses: actions/checkout@v4

Check failure on line 29 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

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

Check failure on line 36 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

36:1 [trailing-spaces] trailing spaces
- name: Free up additional disk space
# https://docs.github.com/en/actions/learn-github-actions/expressions
if: "${{ contains(inputs.target, 'amd') || contains(inputs.target, 'cuda') || contains(inputs.target, 'intel') ||
contains(inputs.target, 'pytorch') || contains(inputs.target, 'tensorflow') }}"
run: |
set -x

Check failure on line 43 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

43:1 [trailing-spaces] trailing spaces
df -h

Check failure on line 45 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

45:1 [trailing-spaces] trailing spaces
sudo rm -rf /usr/local/lib/android &
sudo rm -rf /usr/local/share/boost &
sudo rm -rf /usr/local/lib/node_modules &
sudo rm -rf /usr/share/dotnet &
sudo rm -rf /opt/ghc &
sudo rm -rf /opt/hostedtoolcache/CodeQL &

Check failure on line 52 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

52:1 [trailing-spaces] trailing spaces
sudo docker image prune --all --force &

Check failure on line 54 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

54:1 [trailing-spaces] trailing spaces
wait

df -h

- name: Mount lvm overlay for podman builds
run: |
df -h
free -h
bash ./ci/cached-builds/gha_lvm_overlay.bash

df -h
free -h

# https://github.com/containers/buildah/issues/2521#issuecomment-884779112
- name: Workaround https://github.com/containers/podman/issues/22152#issuecomment-2027705598
run: sudo apt-get -qq remove podman crun

- uses: actions/cache@v4
id: cached-linuxbrew
with:
path: /home/linuxbrew/.linuxbrew
key: linuxbrew

- name: Install podman
if: steps.cached-linuxbrew.outputs.cache-hit != 'true'
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
/home/linuxbrew/.linuxbrew/bin/brew install podman
- name: Add linuxbrew to PATH
run: echo "/home/linuxbrew/.linuxbrew/bin/" >> $GITHUB_PATH

- name: Configure Podman
run: |
mkdir -p $HOME/.config/containers/
cp ci/cached-builds/containers.conf $HOME/.config/containers/containers.conf
cp ci/cached-builds/storage.conf $HOME/.config/containers/storage.conf
# should at least reset storage when touching storage.conf
podman system reset --force
mkdir -p $HOME/.local/share/containers/storage/tmp

# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
- name: "push: make ${{ inputs.target }}"
run: "make ${{ inputs.target }}"
if: "${{ fromJson(inputs.github).event_name == 'push' }}"
env:
IMAGE_TAG: "${{ github.ref_name }}_${{ github.sha }}"
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"

# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
- name: "pull_request: make ${{ inputs.target }}"
run: |
# start a black hole container registry as make target always does a push
mkdir -p $HOME/.config/containers/registries.conf.d/
cp ci/cached-builds/insecure_localhost_registry.conf $HOME/.config/containers/registries.conf.d/insecure_localhost_registry.conf
go run ci/cached-builds/dev_null_container_registry.go &
# build and push the image
make ${{ inputs.target }}
if: "${{ fromJson(inputs.github).event_name == 'pull_request' }}"
env:
IMAGE_TAG: "${{ github.sha }}"
IMAGE_REGISTRY: "localhost:5000/workbench-images"
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }}"

- run: df -h
if: "${{ !cancelled() }}"

Check warning on line 124 in .github/workflows/build-notebooks-TEMPLATE.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

124:5 [new-line-at-end-of-file] no new line character at the end of file
42 changes: 42 additions & 0 deletions .github/workflows/build-notebooks-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
"name": "Build Notebooks"
"on":
"pull_request":

permissions:
contents: read
packages: read
pull-requests: read

jobs:
gen:
name: Generate job matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.gen.outputs.matrix }}
has_jobs: ${{ steps.gen.outputs.has_jobs }}
steps:
- uses: actions/checkout@v4

- run: |
python3 ci/cached-builds/gen_gha_matrix_jobs.py \
--owner=${{ github.repository_owner }} \
--repo=${{ github.event.pull_request.base.repo.name }} \
--pr-number=${{ github.event.pull_request.number }} \
--skip-unchanged
id: gen
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build:
needs: ["gen"]
strategy:
fail-fast: false
matrix: "${{ fromJson(needs.gen.outputs.matrix) }}"
uses: ./.github/workflows/build-notebooks-TEMPLATE.yaml
if: ${{ fromJson(needs.gen.outputs.has_jobs) }}
with:
target: "${{ matrix.target }}"
github: "${{ toJSON(github) }}"
secrets: inherit

Check warning on line 42 in .github/workflows/build-notebooks-pr.yaml

View workflow job for this annotation

GitHub Actions / code-static-analysis

42:5 [new-line-at-end-of-file] no new line character at the end of file
Loading

0 comments on commit 575f9bf

Please sign in to comment.