diff --git a/.github/actions/build/action.yaml b/.github/actions/build/action.yaml new file mode 100644 index 00000000..8d93258a --- /dev/null +++ b/.github/actions/build/action.yaml @@ -0,0 +1,8 @@ +name: Build + +runs: + using: composite + steps: + - name: Build + shell: bash + run: cmake --build --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} diff --git a/.github/actions/install-requirements/action.yaml b/.github/actions/install-requirements/action.yaml new file mode 100644 index 00000000..1d521458 --- /dev/null +++ b/.github/actions/install-requirements/action.yaml @@ -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 }} diff --git a/.github/actions/set-environment-variables/action.yaml b/.github/actions/set-environment-variables/action.yaml new file mode 100644 index 00000000..89627d97 --- /dev/null +++ b/.github/actions/set-environment-variables/action.yaml @@ -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 diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml new file mode 100644 index 00000000..97fa4eac --- /dev/null +++ b/.github/actions/test/action.yaml @@ -0,0 +1,8 @@ +name: Test + +runs: + using: composite + steps: + - name: Test + shell: bash + run: ctest --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} diff --git a/.github/actions/update-packages/action.yaml b/.github/actions/update-packages/action.yaml new file mode 100644 index 00000000..0f0b1252 --- /dev/null +++ b/.github/actions/update-packages/action.yaml @@ -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 diff --git a/.github/workflows/build-and-test-debug-on-push.yaml b/.github/workflows/build-and-test-debug-on-push.yaml deleted file mode 100644 index 75128eff..00000000 --- a/.github/workflows/build-and-test-debug-on-push.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: Build and test Debug binaries on push - -on: - push: - branches-ignore: - - main - -jobs: - build-debug: - uses: ./.github/workflows/build-and-test.yaml - with: - build-type: Debug diff --git a/.github/workflows/build-and-test-debug.yaml b/.github/workflows/build-and-test-debug.yaml new file mode 100644 index 00000000..a09f5e18 --- /dev/null +++ b/.github/workflows/build-and-test-debug.yaml @@ -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 diff --git a/.github/workflows/build-and-test-release-on-merge.yaml b/.github/workflows/build-and-test-release-on-merge.yaml deleted file mode 100644 index 5a5ddd69..00000000 --- a/.github/workflows/build-and-test-release-on-merge.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: Build and test Release binaries on merge - -on: - push: - branches: - - main - -jobs: - build-release: - uses: ./.github/workflows/build-and-test.yaml - with: - build-type: Release diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml deleted file mode 100644 index d9a93492..00000000 --- a/.github/workflows/build-and-test.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Build and test Release/Debug binaries - -on: - workflow_call: - inputs: - build-type: - description: Release or Debug - required: true - type: string - -jobs: - build-x86-64: - runs-on: ubuntu-latest - steps: - - name: Checkout source code of the repository - uses: actions/checkout@v3 - - - name: Update packages - run: | - sudo apt-get update - sudo apt-get upgrade -y - - - name: Set environment variables - run: | - buildType=${{ inputs.build-type }} - echo "CAPITALISED_BUILD_TYPE="${buildType}"" >> $GITHUB_ENV - echo "LOWERCASE_BUILD_TYPE="${buildType,,}"" >> $GITHUB_ENV - - - name: Install requirements - run: | - sudo apt-get install -y libelf-dev - sudo apt-get install -y libboost-all-dev - sudo apt-get install -y libfmt-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 }} - - - name: Configure Release - run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} -DBUILD_TESTS=OFF - if: ${{ env.LOWERCASE_BUILD_TYPE == 'release' }} - - - name: Configure Debug - run: cmake --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} - if: ${{ env.LOWERCASE_BUILD_TYPE == 'debug' }} - - - name: Build - run: cmake --build --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} - - - name: Test - run: ctest --preset conan-${{ env.LOWERCASE_BUILD_TYPE }} diff --git a/.github/workflows/build-test-and-publish-release.yaml b/.github/workflows/build-test-and-publish-release.yaml new file mode 100644 index 00000000..2c664caf --- /dev/null +++ b/.github/workflows/build-test-and-publish-release.yaml @@ -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 diff --git a/.gitignore b/.gitignore index a55d082f..87ae2c61 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ **/vmlinux.h /compile_commands.json /.cache + +!/.github/actions/build \ No newline at end of file