Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
- upload charm to temporary branch for testing
- cross-release to edge on push
- Add separate CI job to select Charmhub channels
- Upload the charm in a separate job, outside of the integration tests.
- Rename the `bootstrap` job to `integration`.
- Disable CI runs on `pull_request`
- Introduce a `CHARM_NAME` variable, which can be set on a fork to upload the charm to a different URL.
- Allow overriding the charm name in the `charmcraft_tokengen.sh` script
  • Loading branch information
barrettj12 committed Oct 18, 2023
1 parent 020c2f5 commit d22aeba
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .github/charmcraft-tokengen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Generate a Charmcraft token to use in the CI pipeline
# The token will be outputted to the file 'charmcraft_token'
# It should be added as a GitHub secret under the name 'CHARMCRAFT_AUTH'
CHARM_NAME=${CHARM_NAME:-juju-controller}
charmcraft login --export=charmcraft_token \
--charm=juju-qa-controller \
--charm="$CHARM_NAME" \
--permission=package-manage-releases \
--permission=package-manage-revisions \
--permission=package-view \
Expand Down
144 changes: 92 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
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:
pull_request:
workflow_dispatch:
env:
CHARM_NAME: ${{ vars.CHARM_NAME }}

jobs:

Expand Down Expand Up @@ -33,18 +38,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 +122,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 +156,8 @@ jobs:
run: |
sg snap_microk8s <<EOF
juju bootstrap microk8s c \
--controller-charm-path=$CHARMHUB_NAME \
--controller-charm-channel=$CHARMHUB_CHANNEL
--controller-charm-path=$CHARM_NAME \
--controller-charm-channel=${{ needs.channel.outputs.test }}
EOF
- name: Check charm status
Expand All @@ -115,46 +168,33 @@ 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
env:
CHANNEL: ${{ needs.channel.outputs.test }}
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
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: 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 }}

0 comments on commit d22aeba

Please sign in to comment.