-
Notifications
You must be signed in to change notification settings - Fork 11
173 lines (161 loc) · 7.05 KB
/
build_charm.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
# Usage documentation: build_charm.md
on:
workflow_call:
inputs:
cache:
description: |
Whether to use cache for faster builds
Should be `false` for production builds
default: false
type: boolean
artifact-prefix:
description: Charm packages are uploaded to GitHub artifacts beginning with this prefix
required: false
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-prefix:
description: Charm packages are uploaded to GitHub artifacts beginning with this prefix
value: ${{ jobs.collect-bases.outputs.artifact-prefix-with-inputs }}
jobs:
collect-bases:
name: Collect bases for charm | ${{ inputs.path-to-charm-directory }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Get workflow version
id: workflow-version
uses: canonical/get-workflow-version-action@v1
with:
repository-name: canonical/data-platform-workflows
file-name: build_charm.yaml
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install CLI
run: pipx install git+https://github.com/canonical/data-platform-workflows@'${{ steps.workflow-version.outputs.sha }}'#subdirectory=python/cli
- name: Checkout
uses: actions/checkout@v4
- name: Collect charm bases to build from charmcraft.yaml
id: collect
run: collect-charm-bases --directory='${{ inputs.path-to-charm-directory }}' --cache='${{ inputs.cache }}'
outputs:
bases: ${{ steps.collect.outputs.bases }}
artifact-prefix-with-inputs: ${{ inputs.artifact-prefix || steps.collect.outputs.default_prefix }}
build:
strategy:
matrix:
base: ${{ fromJSON(needs.collect-bases.outputs.bases) }}
name: 'Build charm | base #${{ matrix.base.id }}'
needs:
- collect-bases
runs-on: ${{ matrix.base.runner }}
timeout-minutes: 120
steps:
- name: (GitHub-hosted ARM runner) Install libpq-dev
if: ${{ matrix.base.runner == 'Ubuntu_ARM64_4C_16G_02' }}
# Needed for `charmcraftcache` to resolve dependencies (for postgresql charms with psycopg2)
run: |
sudo apt-get update
sudo apt-get install libpq-dev -y
- name: Get workflow version
id: workflow-version
uses: canonical/get-workflow-version-action@v1
with:
repository-name: canonical/data-platform-workflows
file-name: build_charm.yaml
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install CLI
run: pipx install git+https://github.com/canonical/data-platform-workflows@'${{ steps.workflow-version.outputs.sha }}'#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@v4
- 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 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
pipx install charmcraftcache
- run: snap list
- name: Pack charm
id: pack
working-directory: ${{ inputs.path-to-charm-directory }}
run: |
if '${{ inputs.cache }}'
then
sg lxd -c "charmcraftcache pack -v --bases-index='${{ matrix.base.id }}'"
else
# Workaround for https://github.com/canonical/charmcraft/issues/1389 on charmcraft 2
touch requirements.txt
sg lxd -c "charmcraft pack -v --bases-index='${{ matrix.base.id }}'"
fi
env:
# Used by charmcraftcache (to avoid GitHub API rate limit)
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload charmcraft logs
if: ${{ failure() && steps.pack.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: logs-charmcraft-build-${{ needs.collect-bases.outputs.artifact-prefix-with-inputs }}-base-${{ matrix.base.id }}
path: ~/.local/state/charmcraft/log/
if-no-files-found: error
- run: touch .empty
- name: Upload charm package
uses: actions/upload-artifact@v4
with:
name: ${{ needs.collect-bases.outputs.artifact-prefix-with-inputs }}-base-${{ matrix.base.id }}
# .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