Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI #45

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 83 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
push:
pull_request:
workflow_dispatch:
env:
CHARM_NAME: ${{ vars.CHARM_NAME }}

jobs:

Expand Down Expand Up @@ -33,18 +35,77 @@ jobs:
with:
artifact-name: charm-packed

bootstrap:
name: "Bootstrap"

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 --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
needs: [build, upload, channel]
strategy:
fail-fast: false
matrix:
cloud: ["lxd", "microk8s"]
env:
LOCAL_CHARM_PATH: ${{ github.workspace }}/controller.charm
CHARMHUB_NAME: juju-qa-controller
CHARMHUB_CHANNEL: latest/edge/${{ github.run_id }}

steps:
- name: Download packed charm
Expand All @@ -58,17 +119,6 @@ jobs:
mv ${{ steps.download.outputs.download-path }}/*.charm \
$LOCAL_CHARM_PATH

# Currently the only way to get charms on k8s is via Charmhub.
- name: Upload charm to Charmhub
id: charmcraft
if: matrix.cloud == 'microk8s'
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
run: |
sudo snap install charmcraft --classic
charmcraft upload $LOCAL_CHARM_PATH \
--name $CHARMHUB_NAME --release $CHARMHUB_CHANNEL

- name: Save charmcraft logs as artifact
if: always() && steps.charmcraft.outcome != 'skipped'
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -103,8 +153,7 @@ jobs:
run: |
sg snap_microk8s <<EOF
juju bootstrap microk8s c \
--controller-charm-path=$CHARMHUB_NAME \
--controller-charm-channel=$CHARMHUB_CHANNEL
--controller-charm-channel=${{ needs.channel.outputs.test }}
EOF

- name: Check charm status
Expand All @@ -115,46 +164,28 @@ jobs:

# TODO: test integration with dashboard / ha-proxy


release:
name: "Release to edge"
runs-on: ubuntu-latest
needs: [build, bootstrap]
if: github.event_name == 'push'
needs: [upload, channel, integration]
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}

steps:
- name: Download packed charm
id: download
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}
- name: Install Charmcraft
run: |
sudo snap install charmcraft --classic

- name: Select Charmhub channel
id: channel
shell: bash
- name: Get uploaded revision
id: revision
run: |
set -x
case ${{ github.ref_name }} in
3.* | 4.*)
TRACK="${{ github.ref_name }}"
;;
master)
TRACK="latest"
;;
esac
echo "track=$TRACK" >> "$GITHUB_OUTPUT"

if [[ -z $TRACK ]]; then
echo "upload=false" >> "$GITHUB_OUTPUT"
else
echo "upload=true" >> "$GITHUB_OUTPUT"
fi

charmcraft status $CHARM_NAME --format json |
jq ${{ needs.channel.outputs.release }} ...

- name: Upload to Charmhub
if: steps.channel.outputs.upload == 'true'
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
- name: Release to edge
if: github.event_name == 'push' && needs.channel.outputs.release != ''
run: |
sudo snap install charmcraft --classic
charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \
--release ${{ steps.channel.outputs.track }}/edge
charmcraft release $CHARM_NAME \
--revision=${{ steps.revision.outputs.revision }}
--channel=${{ needs.channel.outputs.release }}
Loading