Skip to content

[REMOVE BEFORE FLIGH] Local snap installation #1

[REMOVE BEFORE FLIGH] Local snap installation

[REMOVE BEFORE FLIGH] Local snap installation #1

# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
# Usage documentation: build_charm_without_cache.md
on:
workflow_call:
inputs:
artifact-name:
description: Charm package is uploaded to this GitHub artifact name
default: charm-packed-without-cache
type: string
path-to-charm-directory:
description: Relative path to charm directory from repository directory
default: .
type: string
charmcraft-snap-revision:
description: charmcraft snap revision
required: false
type: string
charmcraft-snap-channel:
description: |
charmcraft snap channel
Cannot be used if `charmcraft-snap-revision` input is passed
required: false
type: string
lxd-snap-revision:
description: |
LXD snap revision
LXD from base runner image will be used if neither `lxd-snap-revision` or `lxd-snap-channel` is passed
required: false
type: string
lxd-snap-channel:
description: |
LXD snap channel
Cannot be used if `lxd-snap-revision` input is passed
LXD from base runner image will be used if neither `lxd-snap-revision` or `lxd-snap-channel` is passed
required: false
type: string
outputs:
artifact-name:
description: Charm package is uploaded to this GitHub artifact name
value: ${{ inputs.artifact-name }}
jobs:
get-workflow-version:
name: Get workflow version
uses: canonical/data-platform-workflows/.github/workflows/_get_workflow_version.yaml

Check failure on line 52 in .github/workflows/build_charms_with_specific_snap_without_cache.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/build_charms_with_specific_snap_without_cache.yaml

Invalid workflow file

invalid value workflow reference: no version specified
with:
repository-name: canonical/data-platform-workflows
file-name: build_charm_without_cache.yaml
build-snap:
name: Build snap
runs-on: ubuntu-latest
outputs:
snap-file: ${{ steps.build-snap.outputs.snap }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
repository: canonical/opensearch-snap
ref: DPE-3106_prometheus_exporter_plugin_added
- id: build-snap
name: Build snap
uses: snapcore/action-build@v1
with:
snapcraft-channel: 7.x/candidate
build:
name: Build charm
needs:
- build-snap
- get-workflow-version
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Install CLI
run: pipx install git+https://github.com/canonical/data-platform-workflows@'${{ needs.get-workflow-version.outputs.version }}'#subdirectory=python/cli
- name: Parse charmcraft version inputs
id: charmcraft-snap-version
run: parse-snap-version --revision='${{ inputs.charmcraft-snap-revision }}' --channel='${{ inputs.charmcraft-snap-channel }}' --revision-input-name=charmcraft-snap-revision --channel-input-name=charmcraft-snap-channel
- name: Parse LXD version inputs
id: lxd-snap-version
run: parse-snap-version --revision='${{ inputs.lxd-snap-revision }}' --channel='${{ inputs.lxd-snap-channel }}' --revision-input-name=lxd-snap-revision --channel-input-name=lxd-snap-channel
- name: Checkout
uses: actions/checkout@v3
- name: Copy snap
run: |
cp ${{ needs.build-snap.outputs.snap-file }} src/
- name: Set up environment
run: |
# Placeholder (so that shellcheck disable does not apply to entire script)
# https://github.com/koalaman/shellcheck/issues/960#issuecomment-318918175
true
# shellcheck disable=SC2078
# (shellcheck sees it as constant, but GitHub Actions expression is not constant between workflow runs)
if [[ '${{ steps.lxd-snap-version.outputs.install_flag }}' ]]
then
sudo snap refresh lxd ${{ steps.lxd-snap-version.outputs.install_flag }}
fi
sudo adduser "$USER" lxd
# `newgrp` does not work in GitHub Actions; use `sg` instead
sg lxd -c "lxd waitready"
sg lxd -c "lxd init --auto"
# Workaround for Docker & LXD on same machine
sudo iptables -F FORWARD
sudo iptables -P FORWARD ACCEPT
sudo snap install charmcraft --classic ${{ steps.charmcraft-snap-version.outputs.install_flag }}
pipx install tox
pipx install poetry
pipx inject poetry poetry-plugin-export
# TODO: Remove after https://github.com/python-poetry/poetry/pull/5980 is closed
poetry config warnings.export false
- name: Pack charm
id: pack
working-directory: ${{ inputs.path-to-charm-directory }}
run: |
if tox list --no-desc | grep --fixed-strings --line-regexp build
then
sg lxd -c "tox run -e build"
else
sg lxd -c "charmcraft pack"
fi
- name: Upload charmcraft logs
if: ${{ failure() && steps.pack.outcome == 'failure' }}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact-name }}-charmcraft-build-logs
path: ~/.local/state/charmcraft/log/
if-no-files-found: error
- name: Upload charm package
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifact-name }}
# .empty file required to preserve directory structure
# See https://github.com/actions/upload-artifact/issues/344#issuecomment-1379232156
path: |
${{ inputs.path-to-charm-directory }}/*.charm
.empty
if-no-files-found: error