-
Notifications
You must be signed in to change notification settings - Fork 9
114 lines (108 loc) · 4.5 KB
/
build_rock.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
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
# Usage documentation: build_rock.md
on:
workflow_call:
inputs:
artifact-prefix:
description: Rock packages are uploaded to GitHub artifacts beginning with this prefix
default: packed-rock
type: string
path-to-rock-directory:
description: Relative path to rock directory from repository directory
default: .
type: string
rockcraft-snap-revision:
description: rockcraft snap revision
required: false
type: string
rockcraft-snap-channel:
description: |
rockcraft snap channel
Cannot be used if `rockcraft-snap-revision` input is passed
required: false
type: string
outputs:
artifact-prefix:
description: Rock packages are uploaded to GitHub artifacts beginning with this prefix
value: ${{ jobs.collect-bases.outputs.artifact-prefix-with-inputs }}
jobs:
collect-bases:
name: Collect platforms for rock | ${{ inputs.path-to-rock-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_rock.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 rock platforms to build from rockcraft.yaml
id: collect
run: collect-rock-bases --directory='${{ inputs.path-to-rock-directory }}'
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 rock | ${{ matrix.base.id }}'
needs:
- collect-bases
runs-on: ${{ matrix.base.runner }}
timeout-minutes: 15
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_rock.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 rockcraft version inputs
id: rockcraft-snap-version
run: parse-snap-version --revision='${{ inputs.rockcraft-snap-revision }}' --channel='${{ inputs.rockcraft-snap-channel }}' --revision-input-name=rockcraft-snap-revision --channel-input-name=rockcraft-snap-channel
- name: Checkout
uses: actions/checkout@v4
- name: Set up environment
run: |
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 rockcraft --classic ${{ steps.rockcraft-snap-version.outputs.install_flag }}
- run: snap list
- name: Pack rock
id: pack
working-directory: ${{ inputs.path-to-rock-directory }}
run: sg lxd -c "rockcraft pack -v --platform='${{ matrix.base.id }}'"
- name: Upload rockcraft logs
if: ${{ failure() && steps.pack.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: logs-rockcraft-build-${{ inputs.artifact-prefix }}-architecture-${{ matrix.base.id }}
path: ~/.local/state/rockcraft/log/
if-no-files-found: error
- run: touch .empty
- name: Upload rock package
uses: actions/upload-artifact@v4
with:
name: ${{ needs.collect-bases.outputs.artifact-prefix-with-inputs }}-architecture-${{ 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-rock-directory }}/*.rock
.empty
if-no-files-found: error