Skip to content

Publish all ROCKs from selected branch #4

Publish all ROCKs from selected branch

Publish all ROCKs from selected branch #4

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"/" -f2)
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}