-
Notifications
You must be signed in to change notification settings - Fork 11
112 lines (106 loc) · 4.56 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
# 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: ${{ inputs.artifact-prefix }}
jobs:
collect-platforms:
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-platforms --directory='${{ inputs.path-to-rock-directory }}'
outputs:
platforms: ${{ steps.collect.outputs.platforms }}
build:
strategy:
matrix:
platform: ${{ fromJSON(needs.collect-platforms.outputs.platforms) }}
name: 'Build rock | ${{ matrix.platform.name }}'
needs:
- collect-platforms
runs-on: ${{ matrix.platform.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 `sudo --user` instead
sudo --user "$USER" --preserve-env --preserve-env=PATH -- env -- lxd waitready
sudo --user "$USER" --preserve-env --preserve-env=PATH -- env -- 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: sudo --user "$USER" --preserve-env --preserve-env=PATH -- env -- rockcraft pack -v --platform='${{ matrix.platform.name }}'
- name: Rockcraft logs
if: ${{ success() || (failure() && steps.pack.outcome == 'failure') }}
run: cat ~/.local/state/rockcraft/log/*
- run: touch .empty
- name: Compute path in artifact
id: path-in-artifact
run: compute-path-in-artifact '${{ inputs.path-to-rock-directory }}'
- name: Upload rock package
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-prefix }}-${{ steps.path-in-artifact.outputs.path }}--platform-${{ matrix.platform.name }}
# .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