Skip to content

chore(deps): update docker/login-action action to v3.6.0 (core22-7) #311

chore(deps): update docker/login-action action to v3.6.0 (core22-7)

chore(deps): update docker/login-action action to v3.6.0 (core22-7) #311

Workflow file for this run

name: Build, test and publish rock
on:
pull_request:
branches:
- 'core2[24]-[78]'
push:
branches:
- 'core2[24]-[78]'
jobs:
build-rock:
strategy:
matrix:
runner: [self-hosted]
arch: [amd64, arm64]
runs-on: ["${{ matrix.runner }}", "${{ matrix.arch }}"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build rock
uses: canonical/craft-actions/rockcraft-pack@main
- name: Get rock name
id: vars
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]
then
echo "rockname=pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT"
else
echo "rockname=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Upload rock
# NOTE: using v3 (for this and other actions) due to node versions
# on self-hosted runners (no node20)
uses: actions/upload-artifact@v4
with:
name: snapcraft-${{ matrix.arch }}-rock
path: '*.rock'
spread-tests:
runs-on: [self-hosted, spread-installed]
needs: [build-rock]
steps:
- name: Cleanup job workspace
run: |
rm -rf "${{ github.workspace }}"
mkdir "${{ github.workspace }}"
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Download rock artifact
uses: actions/download-artifact@v4
with:
name: snapcraft-amd64-rock
path: tests
- name: Run spread
run: spread
publish-rock:
runs-on: [self-hosted, amd64]
needs: [build-rock]
# Not on pull requests; only when they're merged
if: github.event_name == 'push'
permissions:
packages: write
contents: write
steps:
- name: Download rock artifact
uses: actions/download-artifact@v4
with:
pattern: snapcraft-*-rock
merge-multiple: true
- name: Install rockcraft
run: sudo snap install --classic rockcraft
- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish rock to Github Container Registry
run: |
rockcraft.skopeo login ghcr.io -u ${{ github.actor }} -p "${{ secrets.GITHUB_TOKEN }}"
set -x
# Split the base branch name ("core22-7") into core ("core22") and version ("7")
array_ref=(${GITHUB_REF_NAME//-/ })
snapcraft_core=${array_ref[0]}
snapcraft_version=${array_ref[1]}
tag="${snapcraft_version}_${snapcraft_core}"
target_image="ghcr.io/${{github.repository_owner}}/snapcraft"
multi_arch_image_name="${target_image}:${tag}"
# Upload each rock to the container registry
declare -a digests=()
for rock in *.rock; do
digest=$(rockcraft.skopeo --insecure-policy inspect "oci-archive:${rock}" --format "{{ .Digest }}")
digests+=($digest)
source_rock="oci-archive:${rock}"
dest_image="docker://${target_image}@${digest}"
rockcraft.skopeo --insecure-policy copy ${source_rock} ${dest_image}
done
# Create and upload a multi-arch manifest
args=("manifest" "create" "${multi_arch_image_name}")
for digest in "${digests[@]}"; do
args+=(--amend "${target_image}@${digest}")
done
docker "${args[@]}"
manifest=$(docker manifest push "${multi_arch_image_name}")
echo "Image is available at ${target_image}"
echo "Manifest digest: ${manifest}"
echo "Published image: ${multi_arch_image_name}" >> "${GITHUB_STEP_SUMMARY}"
echo "Manifest: ${manifest}" >> "${GITHUB_STEP_SUMMARY}"