Skip to content

Commit 5a1859e

Browse files
authored
Merge pull request #11 from Juke34/continuous-integration
Fix caching and set up push trigger only for the main branch
2 parents 1d577a0 + bd761c8 commit 5a1859e

File tree

4 files changed

+82
-46
lines changed

4 files changed

+82
-46
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: CI
2-
on: [push, pull_request, workflow_dispatch]
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request:
7+
workflow_dispatch:
38

49
concurrency:
510
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -24,12 +29,12 @@ jobs:
2429
steps:
2530

2631
- name: Get the code
27-
uses: actions/checkout@v3
32+
uses: actions/checkout@v4
2833

2934
# Install/cache OpenJDK
3035
- name: Cache OpenJDK
3136
id: cache-openjdk
32-
uses: actions/cache@v3
37+
uses: actions/cache@v4
3338
with:
3439
path: /usr/lib/jvm/java-11-openjdk-amd64
3540
key: ${{ runner.os }}-openjdk-11
@@ -42,7 +47,7 @@ jobs:
4247
# Install/cache Nextflow
4348
- name: Cache Nextflow
4449
id: cache-nextflow
45-
uses: actions/cache@v3
50+
uses: actions/cache@v4
4651
with:
4752
path: /usr/local/bin/nextflow
4853
key: ${{ runner.os }}-nextflow
@@ -51,22 +56,32 @@ jobs:
5156
- name: Install Nextflow
5257
if: ${{ steps.cache-nextflow.outputs.cache-hit != 'true' }}
5358
run: cat .github/workflows/install_nextflow_v24.10.5.sh | bash && mv nextflow /usr/local/bin && chmod +x /usr/local/bin/nextflow
59+
60+
# Check-out the repo under $GITHUB_WORKSPACE so that the job can access it
61+
- uses: actions/checkout@v4
5462

55-
# Build/cache containers
56-
- name: Cache containers
57-
id: cache-containers
58-
uses: actions/cache@v3
63+
- name: Cache Dockerfiles and TAR
64+
id: cache-dockerfiles
65+
uses: actions/cache@v4
5966
with:
60-
key: ${{ runner.os }}-containers
61-
path: /var/lib/docker/overlay2
62-
restore-keys: |
63-
${{ runner.os }}-containers
64-
- name: Build Containers
65-
if: ${{ steps.cache-containers.outputs.cache-hit != 'true'}}
66-
run: bash build_all.sh
67+
path: docker-images.tar
68+
key: ${{ runner.os }}-dockerfiles-${{ hashFiles('docker/**/*') }}
6769

68-
# Check-out the repo under $GITHUB_WORKSPACE so that the job can access it
69-
- uses: actions/checkout@v3
70+
- name: Load cached Docker images
71+
id: load-cache
72+
run: |
73+
if [ -f docker-images.tar ]; then
74+
echo "Loading cached Docker images..."
75+
docker load -i docker-images.tar || true
76+
echo "build=false" >> $GITHUB_ENV
77+
else
78+
echo "No Docker cache found"
79+
echo "build=true" >> $GITHUB_ENV
80+
fi
81+
82+
- name: Build images
83+
if: env.build == 'true' || steps.cache-dockerfiles.outputs.cache-hit != 'true'
84+
run: bash build_images.sh github_action
7085

7186
# Run test(s)
7287
- name: test short single

build_all.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

build_images.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env sh
2+
3+
# Run this script with the argument "github_action" in order to save images in an archive for caching
4+
# Pass no arguments to run the script in "normal" build mode suitable for a local machine
5+
6+
# Read first argument as the "build mode"
7+
# The build is used, for instance, for special build commands
8+
# for Github actions.
9+
build_mode=$1
10+
11+
# get architecture
12+
arch=$(uname -m)
13+
# set architecture to docker buildx
14+
docker_arch_option=""
15+
16+
# save original working directory
17+
wd=$(pwd)
18+
19+
# list of image names
20+
image_list=( )
21+
22+
for dir in docker/*
23+
do
24+
cd ${dir}
25+
imgname=$(echo $dir | rev | cut -d/ -f1 | rev)
26+
image_list+=(${imgname})
27+
28+
echo ██████████████████▓▒░ Building ${imgname} ░▒▓██████████████████
29+
30+
# Reditools2 does not compile on arm64, force using amd64 compilation
31+
if [[ $dir =~ "reditools2" ]];then
32+
if [[ "$arch" == arm* || "$arch" == "aarch64" ]]; then
33+
echo "Reditools2 does not compile on arm64, force using amd64 compilation"
34+
docker_arch_option=" --platform linux/amd64"
35+
fi
36+
fi
37+
38+
docker build ${docker_arch_option} -t ${imgname} .
39+
40+
# back to the original working directory
41+
cd $wd
42+
done
43+
44+
if [[ ${build_mode} == 'github_action' ]]; then
45+
echo "Saving docker images to cache..."
46+
docker save ${image_list[@]} -o docker-images.tar
47+
echo Archive size: $(stat --printf="%s" docker-images.tar)
48+
fi

nextflow.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ profiles {
5555
params.aligner = "STAR"
5656
params.reads = "${baseDir}/data/chr21/chr21_small_R1.fastq.gz "
5757
params.genome = "${baseDir}/data/chr21/chr21_small.fasta.gz"
58-
params.annotation = "${baseDir}/data/chr21/chr21_small_filtered.gff3"
58+
params.annotation = "${baseDir}/data/chr21/chr21_small_filtered.gff3.gz"
5959
params.library_type = "ISR"
6060
params.read_type = "short_single"
6161
}
@@ -64,7 +64,7 @@ profiles {
6464
params.aligner = "STAR"
6565
params.reads = "${baseDir}/data/chr21/"
6666
params.genome = "${baseDir}/data/chr21/chr21_small.fasta.gz"
67-
params.annotation = "${baseDir}/data/chr21/chr21_small_filtered.gff3"
67+
params.annotation = "${baseDir}/data/chr21/chr21_small_filtered.gff3.gz"
6868
params.library_type = "ISR"
6969
params.read_type = "short_paired"
7070
}

0 commit comments

Comments
 (0)