Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: Switch to ST124 "shorthand notation" syntax in charmcraft.yaml #253

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build_charm.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ with:
cache: true
```
remember to add your charm's branch(es) to charmcraftcache by running `ccc add` or by [opening an issue](https://github.com/canonical/charmcraftcache-hub/issues/new?assignees=&labels=add-charm&projects=&template=add_charm_branch.yaml&title=Add+charm+branch).

### Required charmcraft.yaml syntax
Only [ST124 - Multi-base platforms in craft tools](https://docs.google.com/document/d/1QVHxZumruKVZ3yJ2C74qWhvs-ye5I9S6avMBDHs2YcQ/edit) "shorthand notation" syntax is supported in charmcraft.yaml

Follow [step #1 from charmcraftst124's documentation](https://github.com/canonical/charmcraftst124?tab=readme-ov-file#step-1-update-charmcraftyaml-to-supported-syntax)
40 changes: 22 additions & 18 deletions .github/workflows/build_charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ on:
outputs:
artifact-prefix:
description: Charm packages are uploaded to GitHub artifacts beginning with this prefix
value: ${{ jobs.collect-bases.outputs.artifact-prefix-with-inputs }}
value: ${{ jobs.collect-platforms.outputs.artifact-prefix-with-inputs }}

jobs:
collect-bases:
name: Collect bases for charm | ${{ inputs.path-to-charm-directory }}
collect-platforms:
name: Collect platforms for charm | ${{ inputs.path-to-charm-directory }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -68,27 +68,32 @@ jobs:
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: Install charmcraftst124
run: pipx install charmcraftst124
- name: Checkout
uses: actions/checkout@v4
- name: Collect charm bases to build from charmcraft.yaml
- name: Check if supported ST124 shorthand notation syntax is used in charmcraft.yaml
working-directory: ${{ inputs.path-to-charm-directory }}
run: charmcraftst124 check-charmcraft-yaml -v
- name: Collect charm platforms to build from charmcraft.yaml
id: collect
run: collect-charm-bases --directory='${{ inputs.path-to-charm-directory }}' --cache='${{ inputs.cache }}'
run: collect-charm-platforms --directory='${{ inputs.path-to-charm-directory }}' --cache='${{ inputs.cache }}'
outputs:
bases: ${{ steps.collect.outputs.bases }}
platforms: ${{ steps.collect.outputs.platforms }}
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 }}'
platform: ${{ fromJSON(needs.collect-platforms.outputs.platforms) }}
name: 'Build charm | ${{ matrix.platform.name }}'
needs:
- collect-bases
runs-on: ${{ matrix.base.runner }}
- collect-platforms
runs-on: ${{ matrix.platform.runner }}
timeout-minutes: 120
steps:
- name: (GitHub-hosted ARM runner) Install libpq-dev
if: ${{ matrix.base.runner == 'Ubuntu_ARM64_4C_16G_02' }}
if: ${{ matrix.platform.runner == 'Ubuntu_ARM64_4C_16G_02' }}
# Needed for `charmcraftcache` to resolve dependencies (for postgresql charms with psycopg2)
run: |
sudo apt-get update
Expand Down Expand Up @@ -136,19 +141,18 @@ jobs:
poetry config warnings.export false

pipx install charmcraftcache
pipx install charmcraftst124
- 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 }}'"
echo 'Cache not yet supported with ST124 syntax'
exit 1
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 }}'"
sg lxd -c "charmcraftst124 pack -v --platform='${{ matrix.platform.name }}'"
fi
env:
# Used by charmcraftcache (to avoid GitHub API rate limit)
Expand All @@ -157,14 +161,14 @@ jobs:
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 }}
name: logs-charmcraft-build-${{ needs.collect-platforms.outputs.artifact-prefix-with-inputs }}-platform-${{ matrix.platform.name_in_artifact }}
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 }}
name: ${{ needs.collect-platforms.outputs.artifact-prefix-with-inputs }}-platform-${{ matrix.platform.name_in_artifact }}
# .empty file required to preserve directory structure
# See https://github.com/actions/upload-artifact/issues/344#issuecomment-1379232156
path: |
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/build_rock.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ jobs:
build:
name: Build rock
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
```
```

### Supported `platforms` syntax in rockcraft.yaml
Only "shorthand notation" is supported

Example rockcraft.yaml
```yaml
platforms:
amd64:
arm64:
```

`build-on` and `build-for` are not supported
22 changes: 11 additions & 11 deletions .github/workflows/build_rock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ on:
outputs:
artifact-prefix:
description: Rock packages are uploaded to GitHub artifacts beginning with this prefix
value: ${{ jobs.collect-bases.outputs.artifact-prefix-with-inputs }}
value: ${{ jobs.collect-platforms.outputs.artifact-prefix-with-inputs }}

jobs:
collect-bases:
collect-platforms:
name: Collect platforms for rock | ${{ inputs.path-to-rock-directory }}
runs-on: ubuntu-latest
timeout-minutes: 5
Expand All @@ -49,19 +49,19 @@ jobs:
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 }}'
run: collect-rock-platforms --directory='${{ inputs.path-to-rock-directory }}'
outputs:
bases: ${{ steps.collect.outputs.bases }}
platforms: ${{ steps.collect.outputs.platforms }}
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 }}'
platform: ${{ fromJSON(needs.collect-platforms.outputs.platforms) }}
name: 'Build rock | ${{ matrix.platform.name }}'
needs:
- collect-bases
runs-on: ${{ matrix.base.runner }}
- collect-platforms
runs-on: ${{ matrix.platform.runner }}
timeout-minutes: 15
steps:
- name: Get workflow version
Expand Down Expand Up @@ -93,19 +93,19 @@ jobs:
- name: Pack rock
id: pack
working-directory: ${{ inputs.path-to-rock-directory }}
run: sg lxd -c "rockcraft pack -v --platform='${{ matrix.base.id }}'"
run: sg lxd -c "rockcraft pack -v --platform='${{ matrix.platform.name }}'"
- 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 }}
name: logs-rockcraft-build-${{ inputs.artifact-prefix }}-platform-${{ matrix.platform.name }}
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 }}
name: ${{ needs.collect-platforms.outputs.artifact-prefix-with-inputs }}-platform-${{ matrix.platform.name }}
# .empty file required to preserve directory structure
# See https://github.com/actions/upload-artifact/issues/344#issuecomment-1379232156
path: |
Expand Down
33 changes: 32 additions & 1 deletion .github/workflows/build_snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,35 @@ jobs:
build:
name: Build snap
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
```
```

### Supported `platforms` and `architectures` syntax in snapcraft.yaml
See https://snapcraft.io/docs/architectures#how-to-create-a-snap-for-a-specific-architecture

#### core24
Only `platforms` is supported. `architectures` is not supported

Only "shorthand notation" is supported

Example snapcraft.yaml
```yaml
platforms:
amd64:
arm64:
```

`build-on` and `build-for` are not supported

#### core22
Only `architectures` is supported. `platforms` is not supported

`architectures` must be a list of dictionaries. Each dictionary in the list must contain a `build-on` key

Example snapcraft.yaml
```yaml
architectures:
- build-on: [amd64]
build-for: [amd64]
- build-on: [arm64]
build-for: [arm64]
```
26 changes: 13 additions & 13 deletions .github/workflows/build_snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ on:
outputs:
artifact-prefix:
description: Snap packages are uploaded to GitHub artifacts beginning with this prefix
value: ${{ jobs.collect-bases.outputs.artifact-prefix-with-inputs }}
value: ${{ jobs.collect-platforms.outputs.artifact-prefix-with-inputs }}

jobs:
collect-bases:
name: Collect architectures for snap | ${{ inputs.path-to-snap-project-directory }}
collect-platforms:
name: Collect platforms for snap | ${{ inputs.path-to-snap-project-directory }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -50,21 +50,21 @@ jobs:
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 snap architectures to build from snapcraft.yaml
- name: Collect snap platforms to build from snapcraft.yaml
id: collect
run: collect-snap-bases --directory='${{ inputs.path-to-snap-project-directory }}'
run: collect-snap-platforms --directory='${{ inputs.path-to-snap-project-directory }}'
outputs:
bases: ${{ steps.collect.outputs.bases }}
platforms: ${{ steps.collect.outputs.platforms }}
artifact-prefix-with-inputs: ${{ inputs.artifact-prefix || steps.collect.outputs.default_prefix }}

build:
strategy:
matrix:
base: ${{ fromJSON(needs.collect-bases.outputs.bases) }}
name: 'Build snap | ${{ matrix.base.id }}'
platform: ${{ fromJSON(needs.collect-platforms.outputs.platforms) }}
name: 'Build snap | ${{ matrix.platform.name }}'
needs:
- collect-bases
runs-on: ${{ matrix.base.runner }}
- collect-platforms
runs-on: ${{ matrix.platform.runner }}
timeout-minutes: 30
steps:
- name: Get workflow version
Expand Down Expand Up @@ -96,19 +96,19 @@ jobs:
- name: Pack snap
id: pack
working-directory: ${{ inputs.path-to-snap-project-directory }}
run: sg lxd -c "snapcraft pack -v --build-for='${{ matrix.base.id }}'"
run: sg lxd -c "snapcraft pack -v --build-for='${{ matrix.platform.name }}'"
- name: Upload snapcraft logs
if: ${{ failure() && steps.pack.outcome == 'failure' }}
uses: actions/upload-artifact@v4
with:
name: logs-snapcraft-build-${{ inputs.artifact-prefix }}-architecture-${{ matrix.base.id }}
name: logs-snapcraft-build-${{ inputs.artifact-prefix }}-platform-${{ matrix.platform.name }}
path: ~/.local/state/snapcraft/log/
if-no-files-found: error
- run: touch .empty
- name: Upload snap package
uses: actions/upload-artifact@v4
with:
name: ${{ needs.collect-bases.outputs.artifact-prefix-with-inputs }}-architecture-${{ matrix.base.id }}
name: ${{ needs.collect-platforms.outputs.artifact-prefix-with-inputs }}-platform-${{ matrix.platform.name }}
# .empty file required to preserve directory structure
# See https://github.com/actions/upload-artifact/issues/344#issuecomment-1379232156
path: |
Expand Down
Loading
Loading