Skip to content

Commit

Permalink
Weekly workflow to build and publish to store (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpm-canonical authored Jun 7, 2024
1 parent bd14cfb commit fcbffc2
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/build-and-publish-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Build and publish snap

on:
schedule:
- cron: "20 2 * * 1" # Monday morning 02:20 UTC
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allow manual trigger
workflow_dispatch:

env:
ARTIFACT_AMD64: matter-all-clusters-app_${{ github.run_number}}_amd64
ARTIFACT_ARM64: matter-all-clusters-app_${{ github.run_number}}_arm64

jobs:
build-amd64:
outputs:
snap: ${{ steps.snapcraft.outputs.snap }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build snap
uses: snapcore/action-build@v1
id: snapcraft

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_AMD64 }}
path: ${{ steps.snapcraft.outputs.snap }}
if-no-files-found: error

publish-amd64:
# Only publish if we are on the main branch
if: github.ref == 'refs/heads/main'
needs: build-amd64
runs-on: ubuntu-latest
steps:
- name: Download locally built snap
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_AMD64 }}

- uses: snapcore/action-publish@v1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }}
with:
snap: ${{ needs.build-amd64.outputs.snap }}
release: latest/edge

build-arm64:
# We do not start the long running arm64 build unless the amd64 build has passed.
needs: build-amd64
outputs:
snap: ${{ steps.snapcraft.outputs.snap }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64

- name: Build snap
uses: diddlesnaps/snapcraft-multiarch-action@v1
id: snapcraft
with:
architecture: arm64

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_ARM64 }}
path: ${{ steps.snapcraft.outputs.snap }}

publish-arm64:
# Only publish if we are on the main branch
if: github.ref == 'refs/heads/main'
needs: [build-arm64]
runs-on: ubuntu-latest
steps:
- name: Download locally built snap
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_ARM64 }}

- uses: snapcore/action-publish@v1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }}
with:
snap: ${{ needs.build-arm64.outputs.snap }}
release: latest/edge

8 changes: 5 additions & 3 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ layout:
parts:
all-clusters:
plugin: nil
build-environment:
- BUILD_METADATA: snap
source: https://github.com/project-chip/connectedhomeip.git
source-depth: 1
source-tag: master
Expand All @@ -41,9 +43,9 @@ parts:
# Shallow clone the submodules
scripts/checkout_submodules.py --shallow --platform linux
# Set the snap version
SHORT_HASH=$(git rev-parse --short HEAD)
craftctl set version=$SHORT_HASH+snap
# prefix the snap version with the upstream tag, or fall back to the commit hash
UPSTREAM_VERSION=$(git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)
craftctl set version=$UPSTREAM_VERSION+$BUILD_METADATA
override-build: |
# The project writes its data to /tmp which isn't persisted.
Expand Down

0 comments on commit fcbffc2

Please sign in to comment.