Enable multiarch build, publish debs as container #53
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: main | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
outputs: | |
short_git_sha: ${{ steps.vars.outputs.SHORT_GIT_SHA }} | |
short_git_version_string: ${{ steps.vars.outputs.SHORT_GIT_VERSION_STRING }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set short git commit SHA | |
id: vars | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
calculatedGitVersionString=$(git log --date=format:%Y%m%d --pretty=~git%cd.%h -n 1) | |
echo "SHORT_GIT_SHA=$calculatedSha" >> $GITHUB_OUTPUT | |
echo "SHORT_GIT_VERSION_STRING=$calculatedGitVersionString" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: amd64,arm64 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Container metadata for tii-px4-msgs | |
id: meta # referenced from later step | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/tiiuae/tii-px4-msgs | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{raw}} | |
type=sha | |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
- name: Build and push debian package container | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: . | |
file: ./Dockerfile | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
PACKAGE_NAME=px4-msgs | |
GIT_RUN_NUMBER=${{ github.run_number }} | |
GIT_COMMIT_HASH=${{ github.sha }} | |
GIT_VERSION_STRING=${{ steps.vars.outputs.SHORT_GIT_VERSION_STRING }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# Needed because we have to create a manifest list in the next job. | |
provenance: mode=min | |
- name: Create container and copy deb packages | |
run: | | |
platforms=("amd64" "arm64") | |
for platform in "${platforms[@]}"; do | |
docker create -ti --name "px4-msgs-build-temp-$platform" --platform=linux/$platform $(echo "${{ steps.meta.outputs.tags }}" | head -1) bash | |
docker cp "px4-msgs-build-temp-$platform:/artifacts/." ./output_dir | |
docker rm "px4-msgs-build-temp-$platform" | |
done | |
- name: Upload .deb packages as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: deb-packages | |
path: ./output_dir/*.deb | |
# upload-to-digitalocean: | |
# runs-on: ubuntu-latest | |
# needs: build-and-push | |
# # if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch | |
# steps: | |
# - name: Download .deb package artifact | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: deb-packages | |
# - name: Upload to digitalocean | |
# run: | | |
# echo "Placeholder" | |
# ls -R |