-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a generic publish.yaml that can be triggered through the UI
- Loading branch information
1 parent
b67e829
commit beee9b1
Showing
4 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/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 output to JSON string format | ||
# { charm_paths: [...] } | ||
CHARM_PATHS_LIST=$(echo "$CHARM_PATHS" | jq -c --slurp --raw-input 'split("\n")[:-1]') | ||
|
||
echo "Found CHARM_PATHS_LIST: $CHARM_PATHS_LIST" | ||
|
||
echo "::set-output name=CHARM_PATHS_LIST::$CHARM_PATHS_LIST" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,82 @@ | ||
# reusable workflow triggered by other actions | ||
# reusable workflow for publishing all charms in this repo | ||
name: Publish | ||
|
||
on: | ||
workflow_call: | ||
secrets: | ||
charmcraft-credentials: | ||
CHARMCRAFT_CREDENTIALS: | ||
required: true | ||
workflow_dispatch: | ||
inputs: | ||
# TODO: Implement this | ||
# source_github_branch: | ||
# description: Source branch to publish | ||
# required: false | ||
# default: 'main' | ||
destination_channel: | ||
description: CharmHub channel to publish to | ||
required: false | ||
default: 'latest/edge' | ||
|
||
jobs: | ||
get-charm-paths: | ||
name: Generate the Charm Matrix | ||
runs-on: ubuntu-latest | ||
outputs: | ||
charm_paths_list: ${{ steps.get-charm-paths.outputs.CHARM_PATHS_LIST }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Get paths for all charms in repo | ||
id: get-charm-paths | ||
run: bash .github/workflows/get-charm-paths.sh | ||
|
||
|
||
publish-charm: | ||
name: Publish Charm | ||
runs-on: ubuntu-latest | ||
needs: get-charm-paths | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
charm: | ||
- mlflow-server | ||
charm-path: ${{ fromJson(needs.get-charm-paths.outputs.charm_paths_list) }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Select charmhub channel | ||
uses: canonical/charming-actions/channel@2.0.0-rc | ||
id: channel | ||
id: select-channel | ||
if: ${{ inputs.destination_channel == '' }} | ||
|
||
# Combine inputs from different sources to a single canonical value so later steps don't | ||
# need logic for picking the right one | ||
- name: Parse and combine inputs | ||
id: parse-inputs | ||
run: | | ||
# destination_channel | ||
destination_channel="${{ inputs.destination_channel || steps.select-channel.outputs.name }}" | ||
echo "setting output of destination_channel=$destination_channel" | ||
echo "::set-output name=destination_channel::$destination_channel" | ||
# tag_prefix | ||
# if charm_path = ./ --> tag_prefix = '' (null) | ||
# if charm_path != ./some-charm (eg: a charm in a ./charms dir) --> tag_prefix = 'some-charm' | ||
if [ ${{ matrix.charm-path }} == './' ]; then | ||
tag_prefix='' | ||
else | ||
tag_prefix=$(basename ${{ matrix.charm-path }} ) | ||
fi | ||
echo "setting output of tag_prefix=$tag_prefix" | ||
echo "::set-output name=tag_prefix::$tag_prefix" | ||
- name: Upload charm to charmhub | ||
uses: canonical/charming-actions/upload-charm@2.0.0-rc | ||
with: | ||
credentials: ${{ secrets.charmcraft-credentials }} | ||
credentials: ${{ secrets.CHARMCRAFT_CREDENTIALS }} | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
charm-path: charms/${{ matrix.charm }} | ||
channel: ${{ steps.channel.outputs.name }} | ||
tag-prefix: ${{ matrix.charm }} | ||
charm-path: ${{ matrix.charm-path }} | ||
channel: ${{ steps.parse-inputs.outputs.destination_channel }} | ||
tag-prefix: ${{ steps.parse-inputs.outputs.tag_prefix }} |