Cleaned CI/CD #54
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Building, Testing and Singularity | ||
on: [push, pull_request] # pull_request really necessary? | ||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# doc: https://github.com/actions/checkout | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Install MPICH | ||
run: sudo apt install libopenmpi-dev | ||
- name: Import GoogleTest | ||
run: git submodule update --init --recursive | ||
# doc: https://google.github.io/googletest/quickstart-cmake.html#create-and-run-a-binary | ||
- name: Build and run the tests | ||
run: | | ||
cmake -S . -B build | ||
cmake --build build | ||
cd build | ||
ctest --rerun-failed --output-on-failure | ||
singularity: | ||
needs: build-and-test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Import GoogleTest | ||
run: git submodule update --init --recursive | ||
# https://github.com/marketplace/actions/cache#skipping-steps-based-on-cache-hit | ||
# https://github.com/actions/cache/blob/main/examples.md#linux-1 | ||
- name: Check Go in the cache | ||
uses: actions/cache@v4.0.2 | ||
id: go_cache | ||
with: | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Set up Go 1.21.10 (iff it's not already in the cache) | ||
if: steps.go_cache.outputs.cache-hit != 'true' | ||
uses: actions/setup-go@v5.0.1 | ||
with: | ||
go-version: '1.21.10' | ||
cache-dependency-path: | | ||
subdir/go.sum | ||
tools/go.sum | ||
id: go | ||
# https://docs.sylabs.io/guides/4.1/admin-guide/installation.html#install-dependencies | ||
- name: Install Dependencies | ||
run: | | ||
cd | ||
sudo apt-get update | ||
sudo apt-get install -y autoconf automake cryptsetup fuse fuse2fs git libfuse-dev libglib2.0-dev libseccomp-dev libtool pkg-config runc squashfs-tools squashfs-tools-ng uidmap wget zlib1g-dev | ||
# OFFICIAL repository commands: | ||
# https://github.com/singularityhub/github-ci/blob/ef8bdf31b2db109a6147824a53de11a36ace22b6/.github/workflows/native-install.yml#L63 | ||
#- name: Download and Compile Singularity (4.1.3) | ||
#env: | ||
#SINGULARITY_VERSION: 4.1.3 | ||
#GOPATH: /tmp/go | ||
#run: | | ||
#mkdir -p $GOPATH | ||
#sudo mkdir -p /usr/local/var/singularity/mnt && \ | ||
#mkdir -p $GOPATH/src/github.com/sylabs && \ | ||
#cd $GOPATH/src/github.com/sylabs && \ | ||
#wget -qO- https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/singularity-ce-${SINGULARITY_VERSION}.tar.gz | \ | ||
#tar xzv && \ | ||
#cd singularity-ce-${SINGULARITY_VERSION} && \ | ||
#./mconfig -p /usr/local && \ | ||
#make -C builddir && \ | ||
#sudo make -C builddir install | ||
- name: Download and Compile Singularity (4.1.3) | ||
env: | ||
SINGULARITY_VERSION: 4.1.3 | ||
run: | | ||
wget https://github.com/sylabs/singularity/releases/download/v${SINGULARITY_VERSION}/singularity-ce_${SINGULARITY_VERSION}-jammy_amd64.deb | ||
sudo dpkg -i singularity-ce_${SINGULARITY_VERSION}-jammy_amd64.deb | ||
- name: Create the singularity container from the def file | ||
run: singularity build --fakeroot matrix-multiplication.sif singularity.def | ||
# https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts#passing-data-between-jobs-in-a-workflow | ||
- name: Upload SIF container | ||
uses: actions/upload-artifact@v4.3.3 | ||
with: | ||
name: singularity-container | ||
path: matrix-multiplication.sif | ||
if-no-files-found: error | ||
compression-level: 9 | ||
overwrite: true | ||
upload-container-to-cluster: | ||
needs: singularity | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Import GoogleTest | ||
run: git submodule update --init --recursive | ||
- name: Download SIF container | ||
uses: actions/download-artifact@v4.1.7 | ||
with: | ||
name: singularity-container | ||
- name: Prepare the zip file to send | ||
run: | | ||
sudo apt install zip && \ | ||
zip -9 -r SE4HPC_project_part2.zip matrixA.txt matrixB.txt matrix-multiplication.sif | ||
- name: Send files to the cluster | ||
env: | ||
CLUSTER_SSH: ${{ secrets.CLUSTER_USERNAME }}@${{ secrets.CLUSTER_HOST }} | ||
run: | | ||
sudo apt install -y sshpass && \ | ||
echo ${{ secrets.CLUSTER_PSW }} > psw.txt && \ | ||
sshpass -f ./psw.txt rsync -PravzHS -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" job.sh $CLUSTER_SSH:. | ||
sshpass -f ./psw.txt rsync -PravzHS -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" SE4HPC_project_part2.zip $CLUSTER_SSH:. | ||
# sshpass -f ./psw.txt rsync -PravzHS -e "ssh -i $SSH_KEY_PATH" -PravzHS job.sh ${{ secrets.CLUSTER_USERNAME }}@${{ secrets.CLUSTER_HOST }}:. | ||
run-container-to-cluster: | ||
needs: upload-container-to-cluster | ||
runs-on: ubuntu-latest | ||
- name: Run job.sh on the cluster | ||
env: | ||
CLUSTER_SSH: ${{ secrets.CLUSTER_USERNAME }}@${{ secrets.CLUSTER_HOST }} | ||
run: | | ||
sshpass -f ./psw.txt ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $CLUSTER_SSH 'unzip -o SE4HPC_project_part2.zip' | ||
sshpass -f ./psw.txt ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $CLUSTER_SSH 'sbatch job.sh' | ||
- name: Download results from the cluster | ||
env: | ||
CLUSTER_SSH: ${{ secrets.CLUSTER_USERNAME }}@${{ secrets.CLUSTER_HOST }} | ||
run: | | ||
sleep 30 | ||
sshpass -f ./psw.txt rsync -PravzHS -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" $CLUSTER_SSH:output.out . | ||
sshpass -f ./psw.txt rsync -PravzHS -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" $CLUSTER_SSH:errors.err . | ||
- name: Upload Output log | ||
uses: actions/upload-artifact@v4.3.3 | ||
with: | ||
name: output | ||
path: output.out | ||
- name: Upload Errors log | ||
uses: actions/upload-artifact@v4.3.3 | ||
with: | ||
name: errors | ||
path: errors.err | ||
#- name: Clean cluster folder | ||
#env: | ||
#CLUSTER_SSH: ${{ secrets.CLUSTER_USERNAME }}@${{ secrets.CLUSTER_HOST }} | ||
#run: sshpass -f ./psw.txt ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $CLUSTER_SSH 'rm -rf *' | ||
# TODO: eventually...? | ||
#- name: Create SSH key | ||
#run: | | ||
#mkdir -p ~/.ssh/ | ||
#ssh-keygen -t rsa -b 4096 -C "${{ secrets.CLUSTER_USERNAME }}@${{ secrets.CLUSTER_HOST }}" -q -N "" -f secret.key && cat secret.key > ../private.key | ||
#sudo chmod 600 ../private.key | ||
#cat secret.key.pub > ~/.ssh/id_rsa.pub | ||
#ssh-keyscan ${{ secrets.CLUSTER_HOST }} > ~/.ssh/known_hosts | ||
#shell: bash | ||
#env: | ||
#SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} | ||
#SSH_KNOWN_HOSTS: ${{secrets.SSH_KNOWN_HOSTS}} | ||
#SSH_KEY_PATH: ${{ github.workspace }}/../private.key |