Skip to content

Commit

Permalink
Add back support for snap & rocks (not ST124 support)
Browse files Browse the repository at this point in the history
Adds support for core24 `platforms` in snapcraft.yaml
  • Loading branch information
carlcsaposs-canonical committed Dec 5, 2024
1 parent 97aab30 commit 3f3491f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 32 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def collect(craft_: craft.Craft):
if craft_ is craft.Craft.SNAP:
craft_file = craft_file.parent / "snap" / craft_file.name
yaml_data = yaml.safe_load(craft_file.read_text())
platforms = []
if craft_ is craft.Craft.CHARM:
# todo: run ccst124 validate
platforms = []
for platform in yaml_data["platforms"]:
# Example `platform`: "[email protected]:amd64"
architecture = craft.Architecture(platform.split(":")[-1])
Expand All @@ -47,9 +46,37 @@ def collect(craft_: craft.Craft):
"name_in_artifact": platform.replace(":", "-"),
}
)
github_actions.output["platforms"] = json.dumps(platforms)
elif craft_ is craft.Craft.ROCK:
for platform in yaml_data["platforms"]:
# Example `platform`: "amd64"
architecture = craft.Architecture(platform)
platforms.append({"name": platform, "runner": RUNNERS[architecture]})
elif craft_ is craft.Craft.SNAP:
if yaml_data["base"] == "core24":
platforms_ = yaml_data["platforms"]
if not isinstance(platforms_, dict):
raise TypeError("Expected type 'dict' for snapcraft.yaml 'platforms'")
for value in platforms_.values():
if value is not None:
raise ValueError(
"Only shorthand notation supported in snapcraft.yaml 'platforms'. "
"'build-on' and 'build-for' not supported"
)
for platform in platforms_:
# Example `platform`: "amd64"
architecture = craft.Architecture(platform)
platforms.append({"name": platform, "runner": RUNNERS[architecture]})
elif yaml_data["base"] == "core22":
for entry in yaml_data["architectures"]:
# Example: "amd64"
platform = entry["build-on"]
architecture = craft.Architecture(platform)
platforms.append({"name": platform, "runner": RUNNERS[architecture]})
else:
raise ValueError(f'Unsupported snapcraft.yaml base: {repr(yaml_data["base"])}')
else:
raise ValueError("ST124 syntax not yet supported for snaps or rocks")
raise ValueError
github_actions.output["platforms"] = json.dumps(platforms)
default_prefix = f'packed-{craft_.value}-{args.directory.replace("/", "-")}'
if craft_ is craft.Craft.CHARM:
default_prefix = f'packed-{craft_.value}-cache-{args.cache}-{args.directory.replace("/", "-")}'
Expand Down
4 changes: 2 additions & 2 deletions python/cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ readme = "README.md"

[tool.poetry.scripts]
redact-secrets = "data_platform_workflows_cli.redact_secrets:main"
collect-snap-bases = "data_platform_workflows_cli.craft_tools.collect_platforms:snap"
collect-rock-bases = "data_platform_workflows_cli.craft_tools.collect_platforms:rock"
collect-snap-platforms = "data_platform_workflows_cli.craft_tools.collect_platforms:snap"
collect-rock-platforms = "data_platform_workflows_cli.craft_tools.collect_platforms:rock"
collect-charm-platforms = "data_platform_workflows_cli.craft_tools.collect_platforms:charm"
release-snap = "data_platform_workflows_cli.craft_tools.release:snap"
release-rock = "data_platform_workflows_cli.craft_tools.release:rock"
Expand Down

0 comments on commit 3f3491f

Please sign in to comment.