From 2e06dc8e3e0e3d601c411185ed4b5d7a4c03a071 Mon Sep 17 00:00:00 2001 From: natalian98 <97316813+natalian98@users.noreply.github.com> Date: Thu, 2 Jun 2022 10:59:56 +0200 Subject: [PATCH] add charming actions (#35) Signed-off-by: natalia --- .github/workflows/get-charm-paths.sh | 31 --------------- .github/workflows/integrate.yaml | 24 ++++++++++-- .github/workflows/on_pull_request.yaml | 23 ++++++++++++ .github/workflows/on_push.yaml | 31 +++++++++++++++ .github/workflows/publish.yaml | 52 ++++++++++++-------------- .github/workflows/release.yaml | 31 +++++++++++++++ 6 files changed, 128 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/get-charm-paths.sh create mode 100644 .github/workflows/on_pull_request.yaml create mode 100644 .github/workflows/on_push.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/get-charm-paths.sh b/.github/workflows/get-charm-paths.sh deleted file mode 100644 index d40c4ac1..00000000 --- a/.github/workflows/get-charm-paths.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -x - -# Finds the charms in this repo, outputing them as JSON -# Will return one of: -# * the relative paths of the directories listed in `./charms`, if that directory exists -# * "./", if the root directory has a "metadata.yaml" file -# * otherwise, error -# -# Modifed from: https://stackoverflow.com/questions/63517732/github-actions-build-matrix-for-lambda-functions/63736071#63736071 -CHARMS_DIR="./charms" -if [ -d "$CHARMS_DIR" ]; -then - CHARM_PATHS=$(find $CHARMS_DIR -maxdepth 1 -type d -not -path '*/\.*' -not -path "$CHARMS_DIR") -else - if [ -f "./metadata.yaml" ] - then - CHARM_PATHS="./" - else - echo "Cannot find valid charm directories - aborting" - exit 1 - fi -fi - -# Convert to JSON in format: -# { charm_paths: [...] } -CHARM_PATHS_JSON=$(echo "$CHARM_PATHS" | jq --slurp --raw-input 'split("\n")[:-1]' | jq "{\"charm-path\": . }" | jq -c) - -echo "Found CHARM_PATHS_JSON: $CHARM_PATHS_JSON" - -echo "::set-output name=CHARM_PATHS_JSON::$CHARM_PATHS_JSON" - diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 57586763..a3de8187 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -1,12 +1,28 @@ +# reusable workflow triggered by other actions name: CI on: - push: - branches: - - main - pull_request: + workflow_call: + secrets: + charmcraft-credentials: + required: true jobs: + + lib-check: + name: Check libraries + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Check libs + uses: canonical/charming-actions/check-libraries@1.0.3 + with: + credentials: "${{ secrets.charmcraft-credentials }}" + github-token: "${{ secrets.GITHUB_TOKEN }}" + unit: name: Unit Test runs-on: ubuntu-latest diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml new file mode 100644 index 00000000..8bfe499b --- /dev/null +++ b/.github/workflows/on_pull_request.yaml @@ -0,0 +1,23 @@ +name: Test and publish to branch + +# On pull_request, we: +# * always publish to charmhub at latest/edge/branchname +# * always run tests + +on: + pull_request: + +jobs: + + tests: + name: Run Tests + uses: ./.github/workflows/integrate.yaml + secrets: + charmcraft-credentials: "${{ secrets.CHARMCRAFT_CREDENTIALS }}" + + # publish runs in parallel with tests, as we always publish in this situation + publish-charm: + name: Publish Charm + uses: ./.github/workflows/publish.yaml + secrets: + charmcraft-credentials: "${{ secrets.CHARMCRAFT_CREDENTIALS }}" diff --git a/.github/workflows/on_push.yaml b/.github/workflows/on_push.yaml new file mode 100644 index 00000000..c6fb21d6 --- /dev/null +++ b/.github/workflows/on_push.yaml @@ -0,0 +1,31 @@ +name: Publish to edge if tests passed + +# On push to a "special" branch, we: +# * always publish to charmhub at latest/edge/branchname +# * always run tests +# where a "special" branch is one of main/master or track/**, as +# by convention these branches are the source for a corresponding +# charmhub edge channel. + +on: + push: + branches: + - master + - main + - track/** + +jobs: + + tests: + name: Run Tests + uses: ./.github/workflows/integrate.yaml + secrets: + charmcraft-credentials: "${{ secrets.CHARMCRAFT_CREDENTIALS }}" + + # publish runs in series with tests, and only publishes if tests passes + publish-charm: + name: Publish Charm + needs: tests + uses: ./.github/workflows/publish.yaml + secrets: + charmcraft-credentials: "${{ secrets.CHARMCRAFT_CREDENTIALS }}" diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c26e427d..f69e76fc 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,42 +1,36 @@ +# reusable workflow triggered by other actions name: Publish on: - push: - branches: - - master - - main - - track/** - pull_request: - branches: - - master - - main - - track/** + workflow_call: + secrets: + charmcraft-credentials: + required: true jobs: - get-charm-matrix: - name: Generate the Charm Matrix - runs-on: ubuntu-latest - outputs: - charm_paths_json: ${{ steps.get-charm-matrix-step.outputs.CHARM_PATHS_JSON }} - steps: - - uses: actions/checkout@v2 - - name: Get paths for all charms in repo - id: get-charm-matrix-step - run: bash ./.github/workflows/get-charm-paths.sh publish-charm: name: Publish Charm runs-on: ubuntu-latest - # Only publish to charmhub if we are pushing to a special branch or running PRs from something named `branch/*` - if: (github.event_name == 'push') || (startsWith( github.head_ref, 'branch/' )) - needs: get-charm-matrix strategy: fail-fast: false - matrix: ${{ fromJson(needs.get-charm-matrix.outputs.charm_paths_json) }} + matrix: + charm: + - jupyter-controller + - jupyter-ui steps: - - uses: actions/checkout@v2 - - uses: canonical/charmhub-upload-action@0.2.0 + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Select charmhub channel + uses: canonical/charming-actions/channel@1.0.3 + id: channel + - name: Upload charm to charmhub + uses: canonical/charming-actions/upload-charm@1.0.3 with: - credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }} - charm-path: ${{ matrix.charm-path }} - charmcraft-channel: latest/edge + credentials: ${{ secrets.charmcraft-credentials }} + github-token: ${{ secrets.GITHUB_TOKEN }} + charm-path: charms/${{ matrix.charm }} + channel: ${{ steps.channel.outputs.name }} + tag-prefix: ${{ matrix.charm }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..6cb93d79 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,31 @@ +# reusable workflow triggered manually +name: Release charm to other tracks and channels + +on: + workflow_dispatch: + inputs: + destination-channel: + description: 'Destination Channel' + required: true + origin-channel: + description: 'Origin Channel' + required: true + charm-name: + description: 'Charm subdirectory name' + required: true + +jobs: + promote-charm: + name: Promote charm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Release charm to channel + uses: canonical/charming-actions/release-charm@1.0.3 + with: + credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }} + github-token: ${{ secrets.GITHUB_TOKEN }} + destination-channel: ${{ github.event.inputs.destination-channel }} + origin-channel: ${{ github.event.inputs.origin-channel }} + tag-prefix: ${{ github.event.inputs.charm-name }} + charm-path: charms/${{ github.event.inputs.charm-name}}