Skip to content

Commit

Permalink
✨ feat: Add tranform to upgrade artifact actions to v4.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Feb 6, 2024
1 parent 94840ec commit 7a74c2c
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/transforms/ci:upgrade-artifact-actions-to-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import replace from '../lib/text/replace.js';
import find from '../lib/text/find.js';

export const description = 'Upgrade artifact actions to v4.';

export const commit = {
type: 'config',
scope: 'ci',
subject: description,
};

const workflowFile = '.github/workflows/ci.yml';
const action = (name, version) => `uses: actions/${name}-artifact@${version}`;

export async function postcondition({read, assert}) {
assert(
await find([action('upload', 'v4')], [workflowFile], {
read,
method: find.exact,
}),
);
assert(
await find([action('download', 'v4')], [workflowFile], {
read,
method: find.exact,
}),
);
assert(
!(await find([action('upload', 'v3')], [workflowFile], {
read,
method: find.exact,
})),
);
assert(
!(await find([action('download', 'v3')], [workflowFile], {
read,
method: find.exact,
})),
);
}

export async function precondition({read, assert}) {
assert(
await find([action('upload', 'v3')], [workflowFile], {
read,
method: find.exact,
}),
);
assert(
await find([action('download', 'v3')], [workflowFile], {
read,
method: find.exact,
}),
);
assert(
!(await find([action('upload', 'v4')], [workflowFile], {
read,
method: find.exact,
})),
);
assert(
!(await find([action('download', 'v4')], [workflowFile], {
read,
method: find.exact,
})),
);
}

export async function apply({read, write}) {
await replace(
[
[action('upload', 'v3'), () => action('upload', 'v4')],
[action('download', 'v3'), () => action('download', 'v4')],
],
[workflowFile],
{
read,
write,
method: replace.all,
},
);
}

export const dependencies = ['ava:test-build'];

0 comments on commit 7a74c2c

Please sign in to comment.