forked from openstack-snaps/ubuntu-openstack-rocks
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from gboutry/publish-all-rocks-job
Publish all rocks job
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 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,90 @@ | ||
name: Publish all ROCKs from selected branch | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
branch: | ||
description: Branch to publish | ||
required: true | ||
default: main | ||
type: choice | ||
options: | ||
- main | ||
- stable/2023.1 | ||
filter: | ||
description: Build/publish only matching ROCKs | ||
required: false | ||
default: '' | ||
type: string | ||
|
||
|
||
jobs: | ||
allrocks: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
rocks: ${{ steps.all-rocks.outputs.rocks }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.branch }} | ||
- name: List rockcraft files | ||
id: list-files | ||
run: | | ||
all_rock_files=$(find rocks -name rockcraft.yaml -printf "%p ") | ||
echo "All rock files: $all_rock_files" | ||
echo "all_rock_files=$all_rock_files" >> $GITHUB_OUTPUT | ||
- name: set output | ||
id: all-rocks | ||
run: | | ||
components=() | ||
# trim file name to component name | ||
for file in ${{ steps.list-files.outputs.all_rock_files }}; do | ||
component=$(echo $file | sed 's/rocks\/\(\S.*\)\/rockcraft.yaml/\1/') | ||
[[ ! -z "$component" ]] && components+=($component) | ||
done | ||
all_rocks=$(echo "\"${components[@]}\"" | jq --compact-output '[. | split(" ") | .[] | select(. | match("${{ inputs.filter }}"))]') | ||
echo "All rocks: $all_rocks" | ||
echo "rocks=$all_rocks" >> $GITHUB_OUTPUT | ||
build-and-publish: | ||
needs: allrocks | ||
if: ${{ needs.allrocks.outputs.rocks != '[]' }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
rock: ${{ fromJson(needs.allrocks.outputs.rocks) }} | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ inputs.branch }} | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@40891eba8c2bcd1309b07ba8b11232f313e86779 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: canonical/craft-actions/rockcraft-pack@main | ||
id: rockcraft | ||
with: | ||
path: rocks/${{ matrix.rock }} | ||
- name: Install skopeo | ||
run: | | ||
sudo snap install --devmode --channel edge skopeo | ||
- name: Install yq | ||
run: | | ||
sudo snap install yq | ||
- name: Import and push to github package | ||
run: | | ||
rock_file="${{ steps.rockcraft.outputs.rock }}" | ||
rockname=$(echo $rock_file | cut -d"_" -f1) | ||
image_name="$(yq '.name' rocks/$rockname/rockcraft.yaml)" | ||
version="$(yq '.version' rocks/$rockname/rockcraft.yaml)" | ||
sudo skopeo \ | ||
--insecure-policy \ | ||
copy \ | ||
oci-archive:"${rock_file}" \ | ||
docker-daemon:"ghcr.io/canonical/${image_name}:${version}" | ||
echo "Publishing rock ${image_name}:${version}" | ||
docker push ghcr.io/canonical/${image_name}:${version} |