SilKit Packaging Workflow #141
This file contains hidden or 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: "SilKit Packaging Workflow" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| silkit_source_repo: | |
| description: 'URL to the sil-kit repository in the form namespace/repo.git' | |
| required: true | |
| type: string | |
| silkit_source_ref: | |
| description: 'Ref of the SIL Kit sources repo.' | |
| required: false | |
| type: string | |
| default: 'main' | |
| silkit_pkg_ref: | |
| description: 'sil-kit-pkg ref. Creates a release if not empty' | |
| required: false | |
| type: string | |
| debian_fullname: | |
| description: 'Name of the maintainer creating the current package' | |
| required: true | |
| type: string | |
| debian_email: | |
| description: 'Email of the maintainer creating the current package' | |
| required: true | |
| type: string | |
| debian_arch: | |
| description: 'Ubuntu CPU arch the package should be build for' | |
| required: true | |
| default: 'amd64' | |
| type: string | |
| env: | |
| PKG_WORKDIR: _i | |
| PKG_OUTDIR: _o | |
| jobs: | |
| get_version: | |
| runs-on: ubuntu-latest | |
| name: Job to get the current SIL KIT Version to package | |
| outputs: | |
| silkit_major: ${{ steps.get_version.outputs.silkit_major }} | |
| silkit_minor: ${{ steps.get_version.outputs.silkit_minor }} | |
| silkit_patch: ${{ steps.get_version.outputs.silkit_patch }} | |
| silkit_suffix: ${{ steps.get_version.outputs.silkit_suffix }} | |
| steps: | |
| - name: Checkout (sil-kit-pkg) | |
| uses: actions/checkout@v4 | |
| with: | |
| path: sil-kit-pkg | |
| - name: Get Version | |
| id: get_version | |
| shell: python | |
| run: | | |
| import os | |
| import re | |
| with open('sil-kit-pkg/debian/changelog', 'r') as cl: | |
| line = cl.readline() | |
| reg = r'libsilkit\s+\(([0-9]+)\.([0-9]+)\.([0-9]+)\~*([A-Za-z]+[0-9]+)?\-[0-9]ubuntu[0-9]\).*' | |
| reg_match = re.match(reg, line) | |
| with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | |
| fh.write(f"silkit_major={reg_match.group(1)}\n") | |
| fh.write(f"silkit_minor={reg_match.group(2)}\n") | |
| fh.write(f"silkit_patch={reg_match.group(3)}\n") | |
| suffix = "" if reg_match.group(4) is None else reg_match.group(4) | |
| fh.write(f"silkit_suffix={suffix}\n") | |
| package_ubuntu: | |
| runs-on: ubuntu-latest | |
| name: Job to build .deb for Ubuntu 20.04+ packages | |
| needs: get_version | |
| container: | |
| image: ghcr.io/vectorgrp/sil-kit-docker-build/sil-kit-ci-packaging-ubuntu-20.04:main | |
| env: | |
| ARTIFACT_NAME: silkit-ubuntu-20.04-deb | |
| steps: | |
| - name: Checkout (sil-kit-pkg) | |
| uses: actions/checkout@v4 | |
| with: | |
| path: sil-kit-pkg | |
| - name: Checkout (sil-kit) | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ inputs.silkit_source_repo }} | |
| submodules: recursive | |
| path: sil-kit | |
| ref: ${{ inputs.silkit_source_ref }} | |
| github-server-url: https://github.com | |
| - name: Install cmake | |
| run: | | |
| sh sil-kit-pkg/.github/actions/fetch_cmake.sh | |
| - name: Build | |
| id: build | |
| env: | |
| DEBFULLNAME: ${{ inputs.debian_fullname }} | |
| DEBEMAIL: ${{ inputs.debian_fullname }} | |
| CI_RUN: "1" | |
| BUILD_SETTINGS: | | |
| { | |
| "SilKitInfo": { | |
| "url": "sil-kit", | |
| "ref": "", | |
| "recursive": true, | |
| "is_local": true | |
| }, | |
| "package_repo_path": "sil-kit-pkg", | |
| "version": { | |
| "major": ${{ needs.get_version.outputs.silkit_major }}, | |
| "minor": ${{ needs.get_version.outputs.silkit_minor }}, | |
| "patch": ${{ needs.get_version.outputs.silkit_patch }}, | |
| "suffix": "${{ needs.get_version.outputs.silkit_suffix }}" | |
| }, | |
| "pkgformat": "deb", | |
| "work_dir": "${{ env.PKG_WORKDIR }}", | |
| "keep_temp": true, | |
| "output_dir": "${{ env.PKG_OUTDIR }}", | |
| "platform": "Ubuntu-20.04", | |
| "debuild": { | |
| "args": ["-d", "--prepend-path=/opt/vector/bin"] | |
| } | |
| } | |
| run: | | |
| mkdir -p $PKG_WORKDIR | |
| mkdir -p $PKG_OUTDIR | |
| touch $PKG_WORKDIR/build_cfg.json | |
| printf %s $BUILD_SETTINGS > $PKG_WORKDIR/build_cfg.json | |
| python3 sil-kit-pkg/scripts/silkit_linux_packaging.py \ | |
| --build-cfg $PKG_WORKDIR/build_cfg.json \ | |
| --verbose | |
| - name: Test Package | |
| id: test | |
| env: | |
| PKG_DIR: ./${{ env.PKG_OUTDIR }} | |
| TEST_DIR: ./sil-kit-pkg/tests/ | |
| run: | | |
| python3 sil-kit-pkg/tests/test_deb.py \ | |
| --package-directory "$PKG_DIR" \ | |
| --test-directory "$TEST_DIR" \ | |
| --distro ubuntu | |
| - name: Artifact | |
| id: artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.ARTIFACT_NAME }} | |
| path: | | |
| ./${{ env.PKG_OUTDIR }}/*.dsc | |
| ./${{ env.PKG_OUTDIR }}/*.build* | |
| ./${{ env.PKG_OUTDIR }}/*.changes | |
| ./${{ env.PKG_OUTDIR }}/*.*deb | |
| retention-days: 1 | |
| package_almalinux: | |
| runs-on: ubuntu-latest | |
| name: Job to build Alma Linux 9 packages | |
| needs: get_version | |
| container: | |
| image: ghcr.io/vectorgrp/sil-kit-docker-build/sil-kit-ci-packaging-fedora-40:main | |
| options: --privileged | |
| env: | |
| ARTIFACT_NAME: silkit-almalinux-9-rpm | |
| steps: | |
| - name: Checkout (sil-kit-pkg) | |
| uses: actions/checkout@v4 | |
| with: | |
| path: sil-kit-pkg | |
| - name: Checkout (sil-kit) | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ inputs.silkit_source_repo }} | |
| submodules: recursive | |
| path: sil-kit | |
| ref: ${{ inputs.silkit_source_ref }} | |
| github-server-url: https://github.com | |
| - name: Build | |
| id: build | |
| env: | |
| CI_RUN: "1" | |
| BUILD_SETTINGS: | | |
| { | |
| "SilKitInfo": { | |
| "url": "sil-kit", | |
| "ref": "", | |
| "recursive": true, | |
| "is_local": true | |
| }, | |
| "package_repo_path": "sil-kit-pkg", | |
| "version": { | |
| "major": ${{ needs.get_version.outputs.silkit_major }}, | |
| "minor": ${{ needs.get_version.outputs.silkit_minor }}, | |
| "patch": ${{ needs.get_version.outputs.silkit_patch }}, | |
| "suffix": "${{ needs.get_version.outputs.silkit_suffix }}" | |
| }, | |
| "pkgformat": "rpm", | |
| "work_dir": "${{ env.PKG_WORKDIR }}", | |
| "keep_temp": true, | |
| "output_dir": "${{ env.PKG_OUTDIR }}", | |
| "platform": "epel9" | |
| } | |
| run: | | |
| mkdir -p $PKG_WORKDIR | |
| mkdir -p $PKG_OUTDIR | |
| touch $PKG_WORKDIR/build_cfg.json | |
| printf %s $BUILD_SETTINGS > $PKG_WORKDIR/build_cfg.json | |
| usermod -a -G mock root | |
| python3 sil-kit-pkg/scripts/silkit_linux_packaging.py \ | |
| --build-cfg $PKG_WORKDIR/build_cfg.json \ | |
| --verbose | |
| - name: Test Package | |
| id: test | |
| env: | |
| PKG_DIR: ./${{ env.PKG_OUTDIR }} | |
| TEST_DIR: ./sil-kit-pkg/tests | |
| run: | | |
| dnf install -y cmake clang ninja-build | |
| python3 sil-kit-pkg/tests/test_deb.py \ | |
| --package-directory "$PKG_DIR" \ | |
| --test-directory "$TEST_DIR" \ | |
| --distro fedora | |
| - name: Artifact | |
| id: artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.ARTIFACT_NAME }} | |
| path: | | |
| ./${{ env.PKG_OUTDIR }}/*.rpm | |
| retention-days: 1 | |
| make-release: | |
| runs-on: ubuntu-latest | |
| needs: [package_ubuntu, package_almalinux] | |
| if: inputs.silkit_pkg_ref != '' | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: download_artifact | |
| uses: actions/download-artifact@v4 | |
| - name: Prepare artifact | |
| run: | | |
| sha256sum silkit-almalinux-9-rpm/* >> ./SHA256 | |
| sha256sum silkit-ubuntu-20.04-deb/* >> ./SHA256 | |
| - name: Prepare GIT tag | |
| id: git_tag | |
| run: | | |
| echo ${{ inputs.silkit_pkg_ref }} | |
| echo ${{ inputs.silkit_pkg_ref }} | sed --expression="s/~rc/-rc/g" | |
| echo "git_tag=$(echo ${{ inputs.silkit_pkg_ref }} | sed --expression="s/~rc/-rc/g")" >> $GITHUB_OUTPUT | |
| case "${{ inputs.silkit_pkg_ref }}" in | |
| *rc* ) | |
| echo 'prerelease=--prerelease' >> $GITHUB_OUTPUT | |
| ;; | |
| *) | |
| echo 'prerelease=' >> $GITHUB_OUTPUT | |
| ;; | |
| esac | |
| - name: Create git tag | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| await github.rest.git.createRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: 'refs/tags/${{ steps.git_tag.outputs.git_tag }}', | |
| sha: context.sha, | |
| }) | |
| } catch(error) { | |
| core.warning("Could not create the specified ref, continuing without it!") | |
| } | |
| - name: Release artifact | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| echo ${{ steps.git_tag.outputs.git_tag }} | |
| gh release create \ | |
| ${{ steps.git_tag.outputs.git_tag }} \ | |
| ${{ github.workspace }}/silkit-ubuntu-20.04-deb/* \ | |
| ${{ github.workspace }}/silkit-almalinux-9-rpm/* \ | |
| SHA256 \ | |
| --verify-tag \ | |
| ${{ steps.git_tag.outputs.prerelease }} \ | |
| --repo "${{ github.repository }}" \ | |
| --title "${{ inputs.silkit_pkg_ref }}" \ | |
| --notes "Ubuntu and Fedora Packages for SIL Kit ${{ steps.git_tag.outputs.git_tag }}" |