From e5b87c0bcf73cf4995fd056c5980a160f01f46cc Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 24 Oct 2022 22:03:45 +0200 Subject: [PATCH] Use new way of outputting values from step/action Refs: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ --- main.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index 4567476..7f6c00b 100644 --- a/main.js +++ b/main.js @@ -1,21 +1,23 @@ const { exec } = require('child_process'); +const fs = require('fs'); + exec(`git for-each-ref --sort=-taggerdate --count 1 --format="%(refname:short)" "refs/tags/*"`, (err, tag, stderr) => { + tag = tag.trim(); + if (err) { console.log('\x1b[33m%s\x1b[0m', 'Could not find any tags because: '); console.log('\x1b[31m%s\x1b[0m', stderr); process.exit(1); - } else if(tag === "") { + } else if (tag === "") { let timestamp = Math.floor(new Date().getTime() / 1000); console.log('\x1b[33m%s\x1b[0m', 'Falling back to default tag'); console.log('\x1b[32m%s\x1b[0m', `Found tag: ${process.env.INPUT_FALLBACK}`); console.log('\x1b[32m%s\x1b[0m', `Found timestamp: ${timestamp}`); - console.log(`::set-output name=tag::${process.env.INPUT_FALLBACK}`); - console.log(`::set-output name=timestamp::${timestamp}`); + fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=${process.env.INPUT_FALLBACK}\r\n`); + fs.appendFileSync(process.env.GITHUB_OUTPUT, `timestamp=${timestamp}\r\n`); process.exit(0); } - tag = tag.trim() - exec(`git log -1 --format=%at ${tag}`, (err, timestamp, stderr) => { if (err) { console.log('\x1b[33m%s\x1b[0m', 'Could not find any timestamp because: '); @@ -23,12 +25,12 @@ exec(`git for-each-ref --sort=-taggerdate --count 1 --format="%(refname:short)" process.exit(1); } - timestamp = timestamp.trim() + timestamp = timestamp.trim(); console.log('\x1b[32m%s\x1b[0m', `Found tag: ${tag}`); console.log('\x1b[32m%s\x1b[0m', `Found timestamp: ${timestamp}`); - console.log(`::set-output name=tag::${tag}`); - console.log(`::set-output name=timestamp::${timestamp}`); + fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=${tag}\r\n`); + fs.appendFileSync(process.env.GITHUB_OUTPUT, `timestamp=${timestamp}\r\n`); process.exit(0); }); });