Skip to content

Commit

Permalink
Publish built binaries as image in OCI registry (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-szweda authored Oct 4, 2023
1 parent af8cd6d commit fbae56d
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 76 deletions.
8 changes: 8 additions & 0 deletions .github/actions/build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Build

runs:
using: composite
steps:
- name: Build
shell: bash
run: cmake --build --preset conan-${{ env.LOWERCASE_BUILD_TYPE }}
14 changes: 14 additions & 0 deletions .github/actions/install-requirements/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Install requirements

runs:
using: composite
steps:
- name: Install requirements
shell: bash
run: |
sudo apt-get install -y libelf-dev
sudo apt-get install -y clang
pip install cmake==3.23.3
pip install conan==2.0
conan profile detect
conan install . --build=missing -s build_type=${{ env.CAPITALISED_BUILD_TYPE }}
30 changes: 30 additions & 0 deletions .github/actions/set-environment-variables/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Set environment variables

inputs:
build-type:
description: Release or Debug
required: true
type: string

runs:
using: composite
steps:
- name: Set environment variables
shell: bash
run: |
buildType=${{ inputs.build-type }}
printf "CAPITALISED_BUILD_TYPE=%s\n" "${buildType}" >> $GITHUB_ENV
printf "LOWERCASE_BUILD_TYPE=%s\n" "${buildType,,}" >> $GITHUB_ENV
newestTag="$(git describe --tags --abbrev=0)"
artifactVersionWithTimestamp="${newestTag}"-"$(date +%Y%m%d_%H%M%S)"
printf "GITHUB_OCI_REGISTRY_ARTIFACT_VERSION=%s\n" "${artifactVersionWithTimestamp}" >> $GITHUB_ENV
printf "RELEASE_PATH=%s\n" "${{ github.workspace }}/build/Release" >> $GITHUB_ENV
repositoryName="$(printf "%s" "${{ github.repository }}" | sed -e "s/^${{ github.repository_owner }}\///")"
lowercaseRepositoryName="${repositoryName,,}"
printf "LOWERCASE_REPOSITORY_NAME=%s\n" "${lowercaseRepositoryName}" >> $GITHUB_ENV
githubOCIRegistryAddress=ghcr.io/${{ github.repository_owner }}/"${lowercaseRepositoryName}"
printf "GITHUB_OCI_REGISTRY_ADDRESS=%s\n" "${githubOCIRegistryAddress}" >> $GITHUB_ENV
8 changes: 8 additions & 0 deletions .github/actions/test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Test

runs:
using: composite
steps:
- name: Test
shell: bash
run: ctest --preset conan-${{ env.LOWERCASE_BUILD_TYPE }}
10 changes: 10 additions & 0 deletions .github/actions/update-packages/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Update packages

runs:
using: composite
steps:
- name: Update packages
shell: bash
run: |
sudo apt-get update
sudo apt-get upgrade -y
12 changes: 0 additions & 12 deletions .github/workflows/build-and-test-debug-on-push.yaml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/build-and-test-debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and test Debug

on:
push:
branches-ignore:
- main

jobs:
build-and-test-debug:
runs-on: ubuntu-latest
steps:
- name: Checkout source code of the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Update packages
uses: ./.github/actions/update-packages

- name: Set environment variables
uses: ./.github/actions/set-environment-variables
with:
build-type: Debug

- name: Set environment variables
uses: ./.github/actions/set-environment-variables
with:
build-type: Debug

- name: Install requirements
uses: ./.github/actions/install-requirements

- name: Configure
shell: bash
run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} -DBUILD_TESTS=ON

- name: Build
uses: ./.github/actions/build

- name: Test
uses: ./.github/actions/test
12 changes: 0 additions & 12 deletions .github/workflows/build-and-test-release-on-merge.yaml

This file was deleted.

52 changes: 0 additions & 52 deletions .github/workflows/build-and-test.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/build-test-and-publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build, test and publish Release

on:
push:
branches:
- main

jobs:
build-test-and-publish-release:
runs-on: ubuntu-latest
steps:
- name: Checkout source code of the repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Update packages
uses: ./.github/actions/update-packages

- name: Set environment variables
uses: ./.github/actions/set-environment-variables
with:
build-type: Release

- name: Install requirements
uses: ./.github/actions/install-requirements

- name: Configure
shell: bash
run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} -DBUILD_TESTS=ON

- name: Build
uses: ./.github/actions/build

- name: Test
uses: ./.github/actions/test

- name: Move license to release directory
run: mv ${{ github.workspace }}/LICENSE ${{ env.RELEASE_PATH }}/LICENSE

- name: Zip release directory contents
run: |
cd ${{ env.RELEASE_PATH }}
zip -r ${{ env.GITHUB_OCI_REGISTRY_ARTIFACT_VERSION }}.zip .
- name: Login to GitHub OCI registry
run: printf "%s" ${{ secrets.GITHUB_TOKEN }} | oras login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Publish zip to GitHub OCI registry
run: |
cd ${{ env.RELEASE_PATH }}
oras push ${{ env.GITHUB_OCI_REGISTRY_ADDRESS }}:${{ env.GITHUB_OCI_REGISTRY_ARTIFACT_VERSION }} ${{ env.GITHUB_OCI_REGISTRY_ARTIFACT_VERSION }}.zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
**/vmlinux.h
/compile_commands.json
/.cache

!/.github/actions/build

0 comments on commit fbae56d

Please sign in to comment.