From 9306967acfd9d7ff0ab5393d3558fe572353c1d2 Mon Sep 17 00:00:00 2001 From: Alex Lowe Date: Wed, 13 Nov 2024 16:00:21 -0500 Subject: [PATCH] feat: charmcraft pack action --- .github/workflows/test-charmcraft.yml | 66 +++++++++++++++++++++++++++ .github/workflows/test.yml | 2 +- charmcraft/pack/action.yaml | 57 +++++++++++++++++++++++ charmcraft/setup/action.yaml | 65 ++++++++++++++++++++++++++ rockcraft-pack/action.yml | 4 +- 5 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/test-charmcraft.yml create mode 100644 charmcraft/pack/action.yaml create mode 100644 charmcraft/setup/action.yaml diff --git a/.github/workflows/test-charmcraft.yml b/.github/workflows/test-charmcraft.yml new file mode 100644 index 0000000..9f7b367 --- /dev/null +++ b/.github/workflows/test-charmcraft.yml @@ -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 }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49004e2..968b72d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,4 +54,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: test-rock_${{ matrix.os }} - path: ${{ steps.rockcraft.outputs.rock }} \ No newline at end of file + path: ${{ steps.rockcraft.outputs.rock }} diff --git a/charmcraft/pack/action.yaml b/charmcraft/pack/action.yaml new file mode 100644 index 0000000..9fe3941 --- /dev/null +++ b/charmcraft/pack/action.yaml @@ -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 diff --git a/charmcraft/setup/action.yaml b/charmcraft/setup/action.yaml new file mode 100644 index 0000000..9b95ece --- /dev/null +++ b/charmcraft/setup/action.yaml @@ -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 diff --git a/rockcraft-pack/action.yml b/rockcraft-pack/action.yml index d63f05e..6a78c97 100644 --- a/rockcraft-pack/action.yml +++ b/rockcraft-pack/action.yml @@ -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: