From c02b57b52f00e5c1028d991dcf9560df6bb7230a Mon Sep 17 00:00:00 2001 From: Jordan Barrett Date: Wed, 18 Oct 2023 12:47:02 +0700 Subject: [PATCH 1/4] Fix CI - new job to select channels - upload in separate job - release job (WIP) --- .github/workflows/ci.yml | 109 ++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64d7d1a..24b8027 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,18 +33,64 @@ jobs: with: artifact-name: charm-packed - bootstrap: - name: "Bootstrap" + + channel: + name: Select Charmhub channel runs-on: ubuntu-latest - needs: build + outputs: + test: ${{ steps.channel.outputs.test }} + release: ${{ steps.channel.outputs.release }} + + steps: + - name: Select Charmhub channel + id: channel + shell: bash + run: | + set -x + case ${{ github.ref_name }} in + 3.* | 4.*) + TRACK="${{ github.ref_name }}" + ;; + master) + TRACK="latest" + ;; + esac + + echo "test=$TRACK/edge/${{ github.sha }}" >> "$GITHUB_OUTPUT" + echo "release=$TRACK/edge" >> "$GITHUB_OUTPUT" + + + 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 \ + --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 - CHARMHUB_NAME: juju-qa-controller - CHARMHUB_CHANNEL: latest/edge/${{ github.run_id }} steps: - name: Download packed charm @@ -103,8 +149,7 @@ jobs: run: | sg snap_microk8s <> "$GITHUB_OUTPUT" - - if [[ -z $TRACK ]]; then - echo "upload=false" >> "$GITHUB_OUTPUT" - else - echo "upload=true" >> "$GITHUB_OUTPUT" - fi - + charmcraft status juju-controller --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' run: | - sudo snap install charmcraft --classic - charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \ - --release ${{ steps.channel.outputs.track }}/edge + charmcraft release juju-controller \ + --revision=${{ steps.revision.outputs.revision }} + --channel=${{ needs.channel.outputs.release }} From 71005988141c8c4f0cff9aa398ab0457d2b3db87 Mon Sep 17 00:00:00 2001 From: Jordan Barrett Date: Wed, 18 Oct 2023 13:04:25 +0700 Subject: [PATCH 2/4] Add Git branch name to Charmhub branch --- .github/workflows/ci.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24b8027..f26ee6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,17 +46,21 @@ jobs: id: channel shell: bash run: | - set -x + set -eux case ${{ github.ref_name }} in 3.* | 4.*) TRACK="${{ github.ref_name }}" ;; - master) + *) TRACK="latest" ;; esac - echo "test=$TRACK/edge/${{ github.sha }}" >> "$GITHUB_OUTPUT" + # 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" echo "release=$TRACK/edge" >> "$GITHUB_OUTPUT" @@ -173,6 +177,8 @@ jobs: run: | sudo snap install charmcraft --classic + # TODO: check if track exists, otherwise don't upload + - name: Get uploaded revision id: revision run: | From 0d989653f3522f00e70eb424a40c59655758f9e7 Mon Sep 17 00:00:00 2001 From: Jordan Barrett Date: Wed, 18 Oct 2023 13:09:07 +0700 Subject: [PATCH 3/4] add CHARM_NAME var - remove extraneous upload step in integration test --- .github/workflows/ci.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f26ee6c..2992f76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,8 @@ on: push: pull_request: workflow_dispatch: +env: + CHARM_NAME: ${{ vars.CHARM_NAME }} jobs: @@ -82,6 +84,7 @@ jobs: run: | sudo snap install charmcraft --classic charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \ + --name $CHARM_NAME \ --release ${{ needs.channel.outputs.test }} @@ -108,17 +111,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 @@ -182,12 +174,12 @@ jobs: - name: Get uploaded revision id: revision run: | - charmcraft status juju-controller --format json | + charmcraft status $CHARM_NAME --format json | jq ${{ needs.channel.outputs.release }} ... - name: Release to edge if: github.event_name == 'push' run: | - charmcraft release juju-controller \ + charmcraft release $CHARM_NAME \ --revision=${{ steps.revision.outputs.revision }} --channel=${{ needs.channel.outputs.release }} From 7a4b257a3d36f1388b6ea3a2792399477f27440a Mon Sep 17 00:00:00 2001 From: Jordan Barrett Date: Wed, 18 Oct 2023 13:26:42 +0700 Subject: [PATCH 4/4] don't release feature branches --- .github/workflows/ci.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2992f76..2e726e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,9 +52,15 @@ jobs: 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 @@ -63,7 +69,9 @@ jobs: BRANCH="${{ github.ref_name }}-${{ github.sha }}" echo "test=$TRACK/edge/$BRANCH" >> "$GITHUB_OUTPUT" - echo "release=$TRACK/edge" >> "$GITHUB_OUTPUT" + if [[ "$DO_RELEASE" == 'true' ]]; then + echo "release=$TRACK/edge" >> "$GITHUB_OUTPUT" + fi upload: @@ -169,8 +177,6 @@ jobs: run: | sudo snap install charmcraft --classic - # TODO: check if track exists, otherwise don't upload - - name: Get uploaded revision id: revision run: | @@ -178,7 +184,7 @@ jobs: jq ${{ needs.channel.outputs.release }} ... - name: Release to edge - if: github.event_name == 'push' + if: github.event_name == 'push' && needs.channel.outputs.release != '' run: | charmcraft release $CHARM_NAME \ --revision=${{ steps.revision.outputs.revision }}