Skip to content

Commit

Permalink
Merge pull request #10 from gboutry/publish-all-rocks-job
Browse files Browse the repository at this point in the history
Publish all rocks job
  • Loading branch information
hemanthnakkina authored Sep 27, 2023
2 parents 4d012b4 + b03fcfe commit 86a7d9f
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/publish_branch.yaml
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}

0 comments on commit 86a7d9f

Please sign in to comment.