Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run-rockcraft-pack-action:
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20.04 is end of standard support

os: [ubuntu-24.04, ubuntu-22.04]
revision: ['1206', '']
runs-on: ${{ matrix.os }}
steps:
Expand Down
24 changes: 23 additions & 1 deletion dist/rockcraft-pack-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20002,6 +20002,9 @@ function expandHome(p) {
function shellUser() {
return os.userInfo().username;
}
function fileExists(path2) {
return fs.existsSync(path2);
}
async function haveExecutable(path2) {
try {
await fs.promises.access(path2, fs.constants.X_OK);
Expand All @@ -20010,6 +20013,9 @@ async function haveExecutable(path2) {
}
return true;
}
async function haveRockcraftTest() {
return await exec.exec("sudo", ["rockcraft", "test", "-h"]) === 0;
}
async function ensureSnapd() {
const haveSnapd = await haveExecutable("/usr/bin/snap");
if (!haveSnapd) {
Expand Down Expand Up @@ -20093,10 +20099,12 @@ var RockcraftBuilder = class {
rockcraftChannel;
rockcraftPackVerbosity;
rockcraftRevision;
runRockcraftTest;
constructor(options) {
this.projectRoot = expandHome(options.projectRoot);
this.rockcraftChannel = options.rockcraftChannel;
this.rockcraftRevision = options.rockcraftRevision;
this.runRockcraftTest = options.runRockcraftTest;
if (allowedVerbosity.includes(options.rockcraftPackVerbosity)) {
this.rockcraftPackVerbosity = options.rockcraftPackVerbosity;
} else {
Expand All @@ -20113,6 +20121,18 @@ var RockcraftBuilder = class {
core2.endGroup();
let rockcraft = "rockcraft pack";
let rockcraftPackArgs = "";
if (this.runRockcraftTest) {
const testFile = `${this.projectRoot}/spread.yaml`;
if (!fileExists(testFile)) {
throw new Error(`Cannot run tests. Missing ${testFile} file.`);
} else if (!await haveRockcraftTest()) {
throw new Error(
"Cannot run tests. rockcraft test is not a valid command."
);
} else {
rockcraft = "rockcraft test";
}
}
if (this.rockcraftPackVerbosity) {
rockcraftPackArgs = `${rockcraftPackArgs} --verbosity ${this.rockcraftPackVerbosity}`;
}
Expand Down Expand Up @@ -20150,6 +20170,7 @@ async function run() {
core3.info(`Building rock in "${projectRoot}"...`);
const rockcraftRevision = core3.getInput("revision");
const rockcraftChannel = core3.getInput("rockcraft-channel") || "stable";
const runRockcraftTest = core3.getInput("test").toLowerCase() === "true";
if (rockcraftRevision.length < 1) {
core3.warning(
`Rockcraft revision not provided. Installing from ${rockcraftChannel}`
Expand All @@ -20160,7 +20181,8 @@ async function run() {
projectRoot,
rockcraftChannel,
rockcraftPackVerbosity,
rockcraftRevision
rockcraftRevision,
runRockcraftTest
});
await builder.pack();
const rock = await builder.outputRock();
Expand Down
6 changes: 6 additions & 0 deletions rockcraft-pack/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ inputs:

If not provided, it defaults to whatever revision is in latest/stable.
default: ''
test:
description: >
Run rockcraft test when packing the rock.

If not provided, it defaults to false.
default: 'false'
outputs:
rock:
description: 'The file name of the resulting rock.'
Expand Down
4 changes: 3 additions & 1 deletion src/rockcraft-pack-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function run(): Promise<void> {
core.info(`Building rock in "${projectRoot}"...`)
const rockcraftRevision = core.getInput('revision')
const rockcraftChannel = core.getInput('rockcraft-channel') || 'stable'
const runRockcraftTest = core.getInput('test').toLowerCase() === 'true'
if (rockcraftRevision.length < 1) {
core.warning(
`Rockcraft revision not provided. Installing from ${rockcraftChannel}`
Expand All @@ -20,7 +21,8 @@ async function run(): Promise<void> {
projectRoot,
rockcraftChannel,
rockcraftPackVerbosity,
rockcraftRevision
rockcraftRevision,
runRockcraftTest
})
await builder.pack()
const rock = await builder.outputRock()
Expand Down
18 changes: 18 additions & 0 deletions src/rockcraft-pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ interface RockcraftBuilderOptions {
rockcraftChannel: string
rockcraftPackVerbosity: string
rockcraftRevision: string
runRockcraftTest: boolean
}

export class RockcraftBuilder {
projectRoot: string
rockcraftChannel: string
rockcraftPackVerbosity: string
rockcraftRevision: string
runRockcraftTest: boolean

constructor(options: RockcraftBuilderOptions) {
this.projectRoot = tools.expandHome(options.projectRoot)
this.rockcraftChannel = options.rockcraftChannel
this.rockcraftRevision = options.rockcraftRevision
this.runRockcraftTest = options.runRockcraftTest
if (allowedVerbosity.includes(options.rockcraftPackVerbosity)) {
this.rockcraftPackVerbosity = options.rockcraftPackVerbosity
} else {
Expand All @@ -44,6 +47,21 @@ export class RockcraftBuilder {

let rockcraft = 'rockcraft pack'
let rockcraftPackArgs = ''

if (this.runRockcraftTest) {
const testFile = `${this.projectRoot}/spread.yaml`

if (!tools.fileExists(testFile)) {
throw new Error(`Cannot run tests. Missing ${testFile} file.`)
} else if (!(await tools.haveRockcraftTest())) {
throw new Error(
'Cannot run tests. rockcraft test is not a valid command.'
)
} else {
rockcraft = 'rockcraft test'
}
}

if (this.rockcraftPackVerbosity) {
rockcraftPackArgs = `${rockcraftPackArgs} --verbosity ${this.rockcraftPackVerbosity}`
}
Expand Down
8 changes: 8 additions & 0 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export function shellUser(): string {
return os.userInfo().username
}

export function fileExists(path: string): boolean {
return fs.existsSync(path)
}

async function haveExecutable(path: string): Promise<boolean> {
try {
await fs.promises.access(path, fs.constants.X_OK)
Expand All @@ -25,6 +29,10 @@ async function haveExecutable(path: string): Promise<boolean> {
return true
}

export async function haveRockcraftTest(): Promise<boolean> {
return (await exec.exec('sudo', ['rockcraft', 'test', '-h'])) === 0
}

export async function ensureSnapd(): Promise<void> {
const haveSnapd = await haveExecutable('/usr/bin/snap')
if (!haveSnapd) {
Expand Down
Loading