Files
wekan/tests/dockerVariantManual.test.cjs
T
Lauri Ojansivu f3f3d21a36 One release publishes all three snaps: wekan, wekan-ondra, wekan-gantt-gpl.
People are still on the older snap names, so a release that publishes only
`wekan` leaves them on a stale package. Two things stood in the way, and both
were in snap-variants.

The job gated EVERYTHING on WEKAN_REPO_TOKEN being able to push to
wekan/<variant>. Building and publishing a snap needs SNAP_AUTH and nothing
else; keeping the variant GitHub repositories in step with wekan/wekan is a
separate, optional thing. Because the two were tied together, a token without
push rights meant no variant snaps at all - that is why v10.48 and v10.49
published none. Now the guard answers two questions instead of one: `snap` (is
SNAP_AUTH set) decides the build and the publish, `sync` (may the token push)
decides only whether the repository is updated, and every "cannot push" warning
ends with "The snap is still built and published".

The variant tree is also no longer taken from a clone of the variant
repository: it is rsynced from the release tag this job checked out, with the
snap name and title sed into both snapcraft files. So the snap is built from
what was just released, whatever state the variant repository is in - and the
optional push sends that same tree on.

Both variants now build on amd64 AND arm64, the two native runners the default
snap uses, instead of amd64 only, and publish to stable + candidate + beta +
edge like the default snap: base core24, grade stable, so all four channels
accept it.

A last guard before the upload: the built file's name must start with the
variant's snap name. A build that produced wekan_*.snap here would overwrite
the DEFAULT snap in the store with a variant.

SNAP_AUTH must carry the ACL for all three names:

  snapcraft export-login --snaps wekan,wekan-ondra,wekan-gantt-gpl \
    --acls package_access,package_push,package_release,package_update \
    snap-auth.txt

tests/releaseWin64AndVariants.test.cjs pins that the build and publish depend
on `snap` and never on `sync`, that the push is the part that needs the token
and runs once per variant, that both variants cover both architectures, and
that a wrongly named snap is refused.

Thanks to xet7 !
2026-07-29 04:04:47 +03:00

107 lines
4.5 KiB
JavaScript

'use strict';
// Guard for publishing the variant Docker images (wekanteam/wekan-gantt-gpl,
// wekanteam/wekan-ondra). Run: node tests/dockerVariantManual.test.cjs
//
// Two things must stay true, and both are decisions rather than details:
//
// * it is MANUAL. release-all.yml publishes wekanteam/wekan on every release;
// the variant images are published when the maintainer decides to. A push,
// tag or schedule trigger sneaking into this workflow would turn "also
// publish that one" into "publish that one every time", which is not what
// was asked for.
// * it RETAGS rather than rebuilds. The variant repositories are byte-identical
// to wekan/wekan apart from the snap name, so the image is the same image;
// `docker buildx imagetools create` copies the manifest, which keeps the
// digests and all five architectures. A rebuild could differ from the
// release it claims to be, and would cost a half-hour emulated build.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
const workflow = read('.github/workflows/docker-variant.yml');
const script = read('releases/docker-publish-variant.sh');
const releaseAll = read('.github/workflows/release-all.yml');
// A comment is not code.
const code = text => text.split('\n').filter(l => !/^\s*#/.test(l)).join('\n');
let passed = 0;
function test(name, fn) {
try {
fn();
passed++;
console.log(' ok -', name);
} catch (err) {
console.error(` FAIL - ${name}\n ${err.message}`);
process.exitCode = 1;
}
}
console.log('dockerVariantManual:');
test('the variant image workflow can only be started by hand', () => {
const triggers = code(workflow).slice(code(workflow).indexOf('\non:'),
code(workflow).indexOf('\npermissions:'));
assert.ok(/workflow_dispatch:/.test(triggers), 'workflow_dispatch is the trigger');
for (const automatic of ['push:', 'schedule:', 'pull_request:', 'release:', 'workflow_run:']) {
assert.ok(!triggers.includes(automatic),
`${automatic} would make it automatic, and it must not be`);
}
});
test('release-all.yml does not publish the variant images', () => {
// The release publishes wekanteam/wekan to Docker Hub, Quay and GHCR. The
// variant images are deliberately not part of that.
for (const variant of ['wekan-gantt-gpl', 'wekan-ondra']) {
const docker = code(releaseAll).split('\n')
.filter(l => l.includes(`wekanteam/${variant}`));
assert.deepStrictEqual(docker, [],
`release-all.yml must not push wekanteam/${variant}`);
}
});
test('it retags the released manifest instead of rebuilding', () => {
for (const [what, text] of [['the workflow', workflow], ['the script', script]]) {
assert.ok(/docker buildx imagetools create/.test(text),
`${what} copies the manifest`);
assert.ok(!/docker buildx build/.test(code(text)),
`${what} must not rebuild - the image is the same image`);
assert.ok(/wekanteam\/wekan:v\$/.test(text),
`${what} takes wekanteam/wekan of that version as the source`);
}
});
test('a variant tag can never cover fewer architectures than wekan does', () => {
const arches = ['linux/amd64', 'linux/arm64', 'linux/ppc64le', 'linux/s390x', 'linux/riscv64'];
for (const [what, text] of [['the workflow', workflow], ['the script', script]]) {
for (const arch of arches) {
assert.ok(text.includes(arch), `${what} names ${arch}`);
}
// Checked on BOTH sides: the source before the retag, and the result after
// it - "pushed" is not the same as "pushed with every platform".
const inspects = text.match(/imagetools inspect/g) || [];
assert.ok(inspects.length >= 2,
`${what} inspects the source AND the pushed tag`);
}
});
test('the credential is checked before anything is pushed', () => {
// Comments first, as usual: the header explains the retag long before any of
// it runs, so the ORDER has to be read from the code.
const body = code(workflow);
const first = body.indexOf('DOCKERHUB_AUTH');
const push = body.indexOf('imagetools create');
assert.ok(first > 0 && first < push,
'DOCKERHUB_AUTH is decoded and logged in with at the top, so a bad token '
+ 'names itself instead of failing inside a push');
assert.ok(/was REJECTED by docker\.io/.test(workflow),
'and says so in one line when the registry refuses it');
});
console.log(`\n${passed} tests passed`);