From 7a74c2cb1b1bd1612c3b0add717268ec2c48c17f Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Tue, 6 Feb 2024 20:49:43 +0100 Subject: [PATCH] :sparkles: feat: Add tranform to upgrade artifact actions to v4. --- .../ci:upgrade-artifact-actions-to-v4.js | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/transforms/ci:upgrade-artifact-actions-to-v4.js diff --git a/src/transforms/ci:upgrade-artifact-actions-to-v4.js b/src/transforms/ci:upgrade-artifact-actions-to-v4.js new file mode 100644 index 0000000..217a310 --- /dev/null +++ b/src/transforms/ci:upgrade-artifact-actions-to-v4.js @@ -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'];