Skip to content

Commit

Permalink
Merge pull request #55 from ngrok/danielle/use-github-actions-for-bui…
Browse files Browse the repository at this point in the history
…lding-and-publishing-to-snapcraft

Fixes uploading/downloading and publishing
  • Loading branch information
dthomasngrokker authored Jan 25, 2025
2 parents 8e48cdc + f4b8d57 commit 9d75267
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
65 changes: 39 additions & 26 deletions .github/workflows/snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,64 @@ on: # The event that triggers the workflow
pull_request:
branches:
- master # When a pull request is opened against master
workflow_dispatch: # Manually trigger the workflow
workflow_dispatch: # When the workflow is manually triggered

jobs:
build:
# Only run this job if the branch name contains "release" or a commit is created on master branch and the branch name contains "release"
if: contains(github.head_ref, 'release') || github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.head_ref, 'release')
# Only run this job if the branch name contains "release" or a commit is created on master branch and the branch name contains "release" or manually triggered
if: contains(github.ref, 'release') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
strategy:
matrix:
architecture: [amd64, i386, armhf, arm64, s390x] #ppc64le]
outputs:
snap-file: ${{ steps.build-snap.outputs.snap }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build the snap # generates .snap file and stores its name in the variable steps.build-snap.outputs.snap
uses: snapcore/action-build@v1
id: build-snap
- name: Set up Snapcraft
run: sudo snap install snapcraft --classic

- name: Install Multipass
run: sudo snap install multipass --classic

# Make sure the snap is installable
- run: |
sudo snap install --dangerous ${{ steps.build-snap.outputs.snap }}
- name: Build the snap # Build the snap for the specified architecture in the matrix strategy above and save the snap file path to an output
id: build-snap
run: |
snapcraft --destructive-mode --enable-experimental-target-arch --target-arch=${{ matrix.architecture }}
SNAP_FILE=$(ls *.snap)
echo "snap=$SNAP_FILE" >> $GITHUB_ENV
echo "snap=$SNAP_FILE" >> $GITHUB_OUTPUT
# Do some testing
- uses: actions/upload-artifact@v4
# Upload the snap file as an artifact
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ngrok
path: ${{ steps.build-snap.outputs.snap }}
name: ngrok-${{ matrix.architecture }}
path: ${{ env.snap }}

publish:
# Only run this job when a commit is created on master branch and the branch name contains 'release'
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.head_ref, 'release')
# Only run this job if the branch name contains "release" or a commit is created on master branch and the branch name contains "release" or manually triggered
if: (github.event_name == 'push' && github.ref == 'refs/heads/master' && contains(github.ref, 'release')) || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
needs: build # Wait for build job to be done
needs: build # Wait for the build job to complete
steps:
- name: Download package
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
name: ngrok
path: .
path: ngrok
pattern: ngrok-*
merge-multiple: true

- run: ls -l ngrok

- name: Publish to Snap Store
uses: snapcore/action-publish@v1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.STORE_LOGIN }}
with:
snap: ${{needs.build.outputs.snap-file}}
# changes on the master branch we would like to publish to the edge risk level, so edge always has the latest changes which may not be considered as stable.
# On the other hand, if we are on a tagged version, we would like to publish to the candidate risk level.
# After thorough testing, the maintainer can manually promote the snap to beta/stable.
release: ${{ startsWith(github.ref, 'refs/tags/') && 'candidate' || 'edge'}}
run: |
sudo snap install snapcraft --classic
for snap in ngrok/*.snap; do
echo "Publishing $snap"
snapcraft push "$snap" --release=stable
done
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ summary: ngrok secure introspectable tunnels to localhost.
description: ngrok is a secure ingress platform that enables developers to add global server load balancing, reverse proxy, firewall, API gateway and Kubernetes Ingress to applications and APIs.

base: core20
grade: stable
grade: devel
confinement: strict

architectures:
Expand Down

0 comments on commit 9d75267

Please sign in to comment.