fix: use charmcraft 2.x to build #208
Workflow file for this run
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: "CI" | |
# We don't run this workflow on 'pull_request', because we require secrets to | |
# upload the charm to Charmhub, and pull_request runs can't access secrets. | |
# PRs should be opened from a branch on the main juju/juju-controller repo, | |
# not from a fork. | |
on: | |
push: | |
workflow_dispatch: | |
env: | |
CHARM_NAME: ${{ vars.CHARM_NAME }} | |
jobs: | |
unit-tests: | |
name: Unit tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
- name: Install dependencies for testing | |
run: | | |
pip install -r requirements-dev.txt | |
- name: Run tests | |
run: | | |
./run_tests | |
build: | |
name: Build charms | |
needs: unit-tests | |
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4 | |
with: | |
artifact-name: charm-packed | |
channel: | |
name: Select Charmhub channel | |
runs-on: ubuntu-latest | |
outputs: | |
test: ${{ steps.channel.outputs.test }} | |
release: ${{ steps.channel.outputs.release }} | |
steps: | |
- name: Select Charmhub channel | |
id: channel | |
shell: bash | |
run: | | |
set -eux | |
case ${{ github.ref_name }} in | |
3.* | 4.*) | |
TRACK="${{ github.ref_name }}" | |
DO_RELEASE=true | |
;; | |
main) | |
TRACK="latest" | |
DO_RELEASE=true | |
;; | |
*) | |
TRACK="latest" | |
DO_RELEASE=false # Don't release feature branches | |
;; | |
esac | |
# Feature branches will be released to the 'latest' track, so we need | |
# to include the branch name to disambiguate. | |
BRANCH="${{ github.ref_name }}-${{ github.sha }}" | |
echo "test=$TRACK/edge/$BRANCH" >> "$GITHUB_OUTPUT" | |
if [[ "$DO_RELEASE" == 'true' ]]; then | |
echo "release=$TRACK/edge" >> "$GITHUB_OUTPUT" | |
fi | |
upload: | |
name: Upload to Charmhub | |
needs: [build, channel] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download packed charm | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ needs.build.outputs.artifact-name }} | |
- name: Upload charm to Charmhub | |
env: | |
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} | |
run: | | |
sudo snap install charmcraft --channel 2.x/stable --classic | |
charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \ | |
--name $CHARM_NAME \ | |
--release ${{ needs.channel.outputs.test }} | |
integration: | |
name: "Integration tests" | |
runs-on: ubuntu-latest | |
needs: [build, upload, channel] | |
strategy: | |
fail-fast: false | |
matrix: | |
cloud: ["lxd", "microk8s"] | |
env: | |
LOCAL_CHARM_PATH: ${{ github.workspace }}/controller.charm | |
steps: | |
- name: Download packed charm | |
id: download | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ needs.build.outputs.artifact-name }} | |
- name: Rename charm file | |
run: | | |
mv ${{ steps.download.outputs.download-path }}/*.charm \ | |
$LOCAL_CHARM_PATH | |
- name: Save charmcraft logs as artifact | |
if: always() && steps.charmcraft.outcome != 'skipped' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: charmcraft-upload-logs | |
path: ~/.local/state/charmcraft/log/ | |
continue-on-error: true | |
- name: Set up LXD | |
if: matrix.cloud == 'lxd' | |
uses: canonical/setup-lxd@90d76101915da56a42a562ba766b1a77019242fd | |
- name: Set up MicroK8s | |
if: matrix.cloud == 'microk8s' | |
uses: balchua/microk8s-actions@v0.3.1 | |
with: | |
channel: "1.25-strict/stable" | |
addons: '["dns", "hostpath-storage"]' | |
- name: Install Juju | |
run: | | |
sudo snap install juju --channel 3.3/beta | |
- name: Bootstrap on LXD | |
if: matrix.cloud == 'lxd' | |
run: | | |
juju bootstrap lxd c \ | |
--controller-charm-path=$LOCAL_CHARM_PATH | |
- name: Bootstrap on MicroK8s | |
if: matrix.cloud == 'microk8s' | |
run: | | |
sg snap_microk8s <<EOF | |
juju bootstrap microk8s c \ | |
--controller-charm-path=$CHARM_NAME \ | |
--controller-charm-channel=${{ needs.channel.outputs.test }} | |
EOF | |
- name: Check charm status | |
run: | | |
juju switch controller | |
juju wait-for application controller --timeout 1m | |
juju status | |
# TODO: test integration with dashboard / ha-proxy | |
release: | |
name: "Release to edge" | |
runs-on: ubuntu-latest | |
needs: [upload, channel, integration] | |
env: | |
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }} | |
steps: | |
- name: Install Charmcraft | |
run: | | |
sudo snap install charmcraft --classic | |
- name: Get uploaded revision | |
id: revision | |
env: | |
CHANNEL: ${{ needs.channel.outputs.test }} | |
run: | | |
set -x | |
TRACK=$(echo $CHANNEL | cut -d '/' -f 1) | |
REVISION=$(charmcraft status $CHARM_NAME --format json | | |
jq ".[] | select(.track == \"$TRACK\") | .mappings[0].releases[] | select(.channel == \"$CHANNEL\") | .revision") | |
echo "revision=$REVISION" >> "$GITHUB_OUTPUT" | |
- name: Release to edge | |
if: github.event_name == 'push' && needs.channel.outputs.release != '' | |
run: | | |
charmcraft release $CHARM_NAME \ | |
--revision=${{ steps.revision.outputs.revision }} \ | |
--channel=${{ needs.channel.outputs.release }} |