Skip to content

Commit

Permalink
Merge pull request #23 from gboutry/refactor/actions
Browse files Browse the repository at this point in the history
Refactor github actions
  • Loading branch information
hemanthnakkina authored Nov 6, 2023
2 parents f4f161e + 312dfa8 commit b36db39
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 108 deletions.
41 changes: 41 additions & 0 deletions .github/actions/publish-rock/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Rock to Registry
description: Publishes a Rock package to the GHCR registry
inputs:
rock:
description: Path to a .rock file
required: true
username:
description: Username to use for the registry
required: true
password:
description: Password to use for the registry
required: true
runs:
using: composite
steps:
- name: Log in to the Container registry
uses: docker/login-action@40891eba8c2bcd1309b07ba8b11232f313e86779
with:
registry: ghcr.io
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Install skopeo
shell: bash
run: sudo snap install --devmode --channel edge skopeo
- name: Install yq
shell: bash
run: sudo snap install yq
- name: Import and push to github package
shell: bash
run: |
rock_file="${{ inputs.rock }}"
rockdir=$(dirname $rock_file)
image_name="$(yq '.name' $rockdir/rockcraft.yaml)"
version="$(yq '.version' $rockdir/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}
36 changes: 36 additions & 0 deletions .github/workflows/build_publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Push

on:
workflow_call:
inputs:
rocks:
description: List of rocks to build
required: true
type: string
default: '[]'
publish:
description: Publish rocks ?
default: false
type: boolean

jobs:
build-and-publish:
if: ${{ inputs.rocks != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rock: ${{ fromJson(inputs.rocks) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: canonical/craft-actions/rockcraft-pack@main
id: rockcraft
with:
path: rocks/${{ matrix.rock }}
- uses: ./.github/actions/publish-rock
if: ${{ inputs.publish }}
with:
rock: ${{ steps.rockcraft.outputs.rock }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Build
name: Modified Rocks

on:
workflow_call:
outputs:
rocks:
description: List of modified rocks as a json string.
value: ${{ jobs.modifiedrocks.outputs.rocks }}


jobs:
Expand All @@ -11,7 +15,7 @@ jobs:
rocks: ${{ steps.changed-rocks.outputs.rocks }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Get changed rockcraft files
id: changed-files
uses: tj-actions/changed-files@v35
Expand All @@ -30,21 +34,3 @@ jobs:
modified_rocks=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${components[@]}")
echo "Modified rocks: $modified_rocks"
echo "rocks=$modified_rocks" >> $GITHUB_OUTPUT
build:
needs: modifiedrocks
if: ${{ needs.modifiedrocks.outputs.rocks != '[]' }}
strategy:
matrix:
rock: ${{ fromJson(needs.modifiedrocks.outputs.rocks) }}
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: canonical/craft-actions/rockcraft-pack@main
id: rockcraft
with:
path: rocks/${{ matrix.rock }}
- uses: actions/upload-artifact@v3
with:
name: rock
path: ${{ steps.rockcraft.outputs.rock }}
41 changes: 0 additions & 41 deletions .github/workflows/publish.yaml

This file was deleted.

44 changes: 4 additions & 40 deletions .github/workflows/publish_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,7 @@ jobs:
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}
uses: ./.github/workflows/build_publish.yaml
with:
rocks: ${{ needs.allrocks.outputs.rocks }}
publish: true
11 changes: 9 additions & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ on:
pull_request:

jobs:
build:
uses: ./.github/workflows/build.yaml
modified_rocks:
uses: ./.github/workflows/modified_rocks.yaml

build-and-publish:
needs: modified_rocks
uses: ./.github/workflows/build_publish.yaml
with:
rocks: ${{ needs.modified_rocks.outputs.rocks }}
publish: false
13 changes: 8 additions & 5 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ on:
- stable/2023.1

jobs:
build:
uses: ./.github/workflows/build.yaml
modified_rocks:
uses: ./.github/workflows/modified_rocks.yaml

publish:
needs: build
uses: ./.github/workflows/publish.yaml
build-and-publish:
needs: modified_rocks
uses: ./.github/workflows/build_publish.yaml
with:
rocks: ${{ needs.modified_rocks.outputs.rocks }}
publish: true

0 comments on commit b36db39

Please sign in to comment.