Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an autofix for lang-go #1117

Merged
merged 5 commits into from
Oct 4, 2023
Merged
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
29 changes: 29 additions & 0 deletions .autofix/fixers/update-lang-go.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const os = require('os');

exports.register = async (fixers) => {
const response = await fetch("https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json");
const data = await response.json();

const versions = data.filter(version => version.stable).flatMap(version => version.version).reverse();

const patchVersionReplacements = {};
for (const version of versions) {
const match = version.match(/^(\d+\.\d+)\.(\d+)$/);
if (!match) {
continue;
}
// Only capturing major and minor versions in the pattern
const segments = version.split('.');
const prefix = segments.slice(0, -1).join('\\.');
const pattern = prefix + '\\.[0-9][0-9]*';
patchVersionReplacements[pattern] = version;
}

fixers[0].push({
id: 'update-lang-go',
cmd: Object.keys(patchVersionReplacements).map(pattern => {
return `sed ${os.type() === 'Darwin' ? '-i "" -E' : '-i -e'} "s/\\(GO_VERSION.*\\)${pattern}/\\1${patchVersionReplacements[pattern]}/g" chunks/lang-go/chunk.yaml`;
}).join('\n'),
description: 'update lang go',
});
};
Loading