Skip to content

Commit

Permalink
feat: charmcraft pack action
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Nov 13, 2024
1 parent 8ccf621 commit 9306967
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 3 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/test-charmcraft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test Charmcraft

on:
pull_request:
paths:
- ".github/workflows/*charmcraft*"
- "charmcraft**"
push:
branches:
- main

jobs:
test-install-success:
strategy:
matrix:
channel: [latest/stable, latest/edge, 2.x/stable]
include:
- revision: 5303
- lxd-channel: latest/stable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./charmcraft/setup
id: setup
with:
channel: ${{ matrix.channel }}
revision: ${{ matrix.revision }}
lxd-channel: ${{ matrix.lxd-channel }}
- name: Check revision number if set with a revision
if: matrix.revision != ''
run: |
[[ ${{ matrix.revision }} == ${{ steps.setup.outputs.charmcraft-revision }} ]]
- name: Check that revisions are set
run: |
test ${{ steps.setup.outputs.charmcraft-revision }} -ge 0
test ${{ steps.setup.outputs.lxd-revision }} -ge 0
test-pack:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
channel: [latest/stable]
include:
- os: ubuntu-24.04
channel: ''
revision: 5303
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: juju/juju
path: juju
ref: main
- name: Pack charm
id: charmcraft
uses: ./charmcraft/pack
with:
path: juju/testcharms/charms/lxd-profile/
channel: ${{ matrix.channel }}
revision: ${{ matrix.revision }}
- name: Upload charm
uses: actions/upload-artifact@v4
with:
name: test-charm_${{ matrix.os }}
path: ${{ steps.charmcraft.outputs.charms }}

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: test-rock_${{ matrix.os }}
path: ${{ steps.rockcraft.outputs.rock }}
path: ${{ steps.rockcraft.outputs.rock }}
57 changes: 57 additions & 0 deletions charmcraft/pack/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Build a charm"
description: "Pack a charm with Charmcraft"
author: "Canonical"
inputs:
path:
description: >
The location of the Charmcraft project.
Defaults to the base of the repository.
default: '.'
verbosity:
description: >
Set the build verbosity level to 'quiet', 'brief', 'verbose', 'debug' or
'trace'.
The default is 'trace'.
default: 'trace'
channel:
description: >
Install the snap from a specific channel
If not provided, it defaults to stable.
default: 'stable'
revision:
description: >
Pin the snap revision to install.
If not provided, it defaults to whatever revision is in latest/stable.
default: ''
outputs:
charms:
description: 'The names of any charm files created.'
value: ${{ steps.pack-charm.outputs.charms }}
runs:
using: 'composite'
steps:
- uses: ./charmcraft/setup
with:
channel: ${{ inputs.channel }}
revision: ${{ inputs.revision }}
- uses: actions/cache@v4
with:
path: ${HOME}/snap/charmcraft/common/cache
key: charmcraft-cache-${{ hashfiles('requirements.txt', '*.lock', 'charmcraft.yaml') }}
restore-keys: |
charmcraft-cache-
- id: pack-charm
shell: bash
env:
CRAFT_VERBOSITY_LEVEL: ${{ inputs.verbosity }}
working-directory: ${{ inputs.path }}
run: |
charmcraft pack
echo "charms=$(ls -1 *.charm | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
branding:
icon: layers
color: orange
65 changes: 65 additions & 0 deletions charmcraft/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Setup Charmcraft"
description: "Install Charmcraft"
author: "Canonical"
inputs:
channel:
description: >
Install the snap from a specific channel
If not provided, it defaults to stable.
default: 'stable'
revision:
description: >
Pin the snap revision to install.
If not provided, it defaults to whatever revision is in latest/stable.
default: ''
lxd-channel:
description: >
The LXD channel to use.
Defaults to the recommended channel for Charmcraft.
default: 5.21/stable
outputs:
lxd-revision:
description: The LXD revision used.
value: ${{ steps.install.outputs.lxd }}
charmcraft-revision:
description: The Charmcraft revision used.
value: ${{ steps.install.outputs.charmcraft }}
runs:
using: 'composite'
steps:
- shell: bash
name: Check system compatibility
run: |
if [[ $(uname -s) != Linux ]]; then
echo "::error::This action only works on Linux runners."
exit 1
fi
if ! which snap; then
echo "::error::This action requires snapd"
fi
- uses: canonical/setup-lxd@main
with:
channel: ${{ inputs.lxd-channel }}
- shell: bash
working-directory: ${{ inputs.path }}
name: Install Charmcraft
id: install
run: |
if [ -n "${{ inputs.revision }}" ]; then
echo "::notice::Using Charmcraft revision ${{ inputs.revision }}"
sudo snap install --revision=${{ inputs.revision }} --classic charmcraft
else
echo "::notice::Using Charmcraft from channel ${{ inputs.channel }}"
sudo snap install --channel=${{ inputs.channel }} --classic charmcraft
fi
echo "::endgroup::"
echo "lxd=$(curl -sS --unix-socket /run/snapd.socket http://localhost/v2/snaps/lxd -X GET | jq .result.revision)" >> "$GITHUB_OUTPUT"
echo "charmcraft=$(curl -sS --unix-socket /run/snapd.socket http://localhost/v2/snaps/charmcraft -X GET | jq .result.revision)" >> "$GITHUB_OUTPUT"
branding:
icon: package
color: orange
4 changes: 2 additions & 2 deletions rockcraft-pack/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ author: "Canonical"
inputs:
path:
description: >
The location of the Rockcraft project.
The location of the Rockcraft project.
Defaults to the base of the repository.
default: '.'
verbosity:
Expand Down

0 comments on commit 9306967

Please sign in to comment.