Skip to content

Commit

Permalink
feat: Add base option for snapcraft (#7320)
Browse files Browse the repository at this point in the history
  • Loading branch information
filfreire authored Dec 19, 2022
1 parent 106e98d commit 2852cb5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-icons-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": major
---

Add base option for snapcraft
3 changes: 3 additions & 0 deletions docs/configuration/snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ The top-level [snap](configuration.md#Configuration-snap) key contains set of op
<!-- do not edit. start of generated block -->
<ul>
<li>
<p><code id="SnapOptions-base">base</code> String | “undefined” - A snap of type base to be used as the execution environment for this snap. Examples: <code>core</code>, <code>core18</code>, <code>core20</code>. Defaults to <code>core18</code></p>
</li>
<li>
<p><code id="SnapOptions-confinement">confinement</code> = <code>strict</code> “devmode” | “strict” | “classic” | “undefined” - The type of <a href="https://snapcraft.io/docs/reference/confinement">confinement</a> supported by the snap.</p>
</li>
<li>
Expand Down
7 changes: 7 additions & 0 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -5098,6 +5098,13 @@
"description": "Whether or not the snap should automatically start on login.",
"type": "boolean"
},
"base": {
"description": "A snap of type base to be used as the execution environment for this snap. Examples: `core`, `core18`, `core20`. Defaults to `core18`",
"type": [
"null",
"string"
]
},
"buildPackages": {
"anyOf": [
{
Expand Down
5 changes: 5 additions & 0 deletions packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { TargetSpecificOptions } from "../core"
import { CommonLinuxOptions } from "./linuxOptions"

export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
/**
* A snap of type base to be used as the execution environment for this snap. Examples: `core`, `core18`, `core20`. Defaults to `core18`
*/
readonly base?: string | null

/**
* The type of [confinement](https://snapcraft.io/docs/reference/confinement) supported by the snap.
* @default strict
Expand Down
3 changes: 3 additions & 0 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export default class SnapTarget extends Target {
if (this.isUseTemplateApp) {
delete appDescriptor.adapter
}
if (options.base != null) {
snap.base = options.base
}
if (options.grade != null) {
snap.grade = options.grade
}
Expand Down
33 changes: 33 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,39 @@ test.ifDevOrLinuxCi(
})
)

test.ifDevOrLinuxCi(
"default base",
app({
targets: snapTarget,
config: {
productName: "Sep",
},
effectiveOptionComputed: async ({ snap }) => {
expect(snap).toMatchSnapshot()
expect(snap.base).toBe("core18")
return true
},
})
)

test.ifDevOrLinuxCi(
"base option",
app({
targets: snapTarget,
config: {
productName: "Sep",
snap: {
base: "core22",
},
},
effectiveOptionComputed: async ({ snap }) => {
expect(snap).toMatchSnapshot()
expect(snap.base).toBe("core22")
return true
},
})
)

test.ifDevOrLinuxCi(
"use template app",
app({
Expand Down

0 comments on commit 2852cb5

Please sign in to comment.