Add script for publishing github release
This commit is contained in:
@@ -193,12 +193,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: ~/alexanderzobnin
|
at: ~/alexanderzobnin
|
||||||
- run:
|
|
||||||
name: Prepare assets
|
|
||||||
command: mv ci/packages/* ./
|
|
||||||
- run:
|
- run:
|
||||||
name: Publish release
|
name: Publish release
|
||||||
command: 'node ./.circleci/github/publishRelease.js'
|
command: 'node ./scripts/github/publishRelease.js'
|
||||||
no_output_timeout: 15m
|
no_output_timeout: 15m
|
||||||
|
|
||||||
make-release-commit:
|
make-release-commit:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class GithubClient {
|
|||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (required && !username && !token) {
|
if (required && (!username || !token)) {
|
||||||
throw new Error('operation needs a GITHUB_USERNAME and GITHUB_ACCESS_TOKEN environment variables');
|
throw new Error('operation needs a GITHUB_USERNAME and GITHUB_ACCESS_TOKEN environment variables');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8,15 +8,25 @@ const GRAFANA_ZABBIX_REPO = 'grafana-zabbix';
|
|||||||
const github = new GithubClient(GRAFANA_ZABBIX_OWNER, GRAFANA_ZABBIX_REPO, true);
|
const github = new GithubClient(GRAFANA_ZABBIX_OWNER, GRAFANA_ZABBIX_REPO, true);
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const tag = process.env.CIRCLE_TAG;
|
let releaseVersion = '';
|
||||||
const tagRegex = /v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)/;
|
if (process.env.CIRCLE_TAG) {
|
||||||
if (!tagRegex.test(tag)) {
|
const tag = process.env.CIRCLE_TAG;
|
||||||
console.error(`Release tag should has format v1.2.3[-meta], got ${tag}`);
|
const tagRegex = /v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)/;
|
||||||
process.exit(1);
|
if (!tagRegex.test(tag)) {
|
||||||
|
console.error(`Release tag should has format v1.2.3[-meta], got ${tag}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion = tag.slice(1);
|
||||||
|
} else {
|
||||||
|
releaseVersion = getPluginVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
const releaseVersion = tag.slice(1);
|
|
||||||
console.log('Release version', releaseVersion);
|
console.log('Release version', releaseVersion);
|
||||||
|
if (!releaseVersion) {
|
||||||
|
console.error('Release not found');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const releaseNotes = `# Grafana-Zabbix ${releaseVersion}`;
|
const releaseNotes = `# Grafana-Zabbix ${releaseVersion}`;
|
||||||
const preRelease = /(alpha|beta)/.test(releaseVersion);
|
const preRelease = /(alpha|beta)/.test(releaseVersion);
|
||||||
@@ -29,7 +39,7 @@ async function main() {
|
|||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
if (reason.response.status !== 404) {
|
if (reason.response.status !== 404) {
|
||||||
// 404 just means no release found. Not an error. Anything else though, re throw the error
|
// 404 just means no release found. Not an error. Anything else though, re throw the error
|
||||||
console.error(reason);
|
console.error(reason.response.data);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +55,7 @@ async function main() {
|
|||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
if (reason.response.status !== 404) {
|
if (reason.response.status !== 404) {
|
||||||
// 404 just means no release found. Not an error. Anything else though, re throw the error
|
// 404 just means no release found. Not an error. Anything else though, re throw the error
|
||||||
console.error(reason);
|
console.error(reason.response.data);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.error('No release tag found');
|
console.error('No release tag found');
|
||||||
@@ -63,10 +73,10 @@ async function main() {
|
|||||||
prerelease: preRelease,
|
prerelease: preRelease,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Release published with id', releaseId);
|
|
||||||
releaseId = newReleaseResponse.data.id;
|
releaseId = newReleaseResponse.data.id;
|
||||||
|
console.log('Release published with id', releaseId);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason.response.data);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -79,7 +89,7 @@ async function main() {
|
|||||||
prerelease: preRelease,
|
prerelease: preRelease,
|
||||||
});
|
});
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason.response.data);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,8 +113,8 @@ async function main() {
|
|||||||
async function publishAssets(fileName, destUrl) {
|
async function publishAssets(fileName, destUrl) {
|
||||||
// Add the assets. Loop through files in the ci/dist folder and upload each asset.
|
// Add the assets. Loop through files in the ci/dist folder and upload each asset.
|
||||||
|
|
||||||
const fileStat = fs.statSync(`${fileName}`);
|
const fileStat = fs.statSync(`${__dirname}/../../ci/packages/${fileName}`);
|
||||||
const fileData = fs.readFileSync(`${fileName}`);
|
const fileData = fs.readFileSync(`${__dirname}/../../ci/packages/${fileName}`);
|
||||||
return await github.client.post(`${destUrl}?name=${fileName}`, fileData, {
|
return await github.client.post(`${destUrl}?name=${fileName}`, fileData, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': resolveContentType(path.extname(fileName)),
|
'Content-Type': resolveContentType(path.extname(fileName)),
|
||||||
@@ -131,4 +141,13 @@ const resolveContentType = (extension) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPluginVersion = () => {
|
||||||
|
const pkg = fs.readFileSync(`${__dirname}/../../package.json`, 'utf8');
|
||||||
|
const { version } = JSON.parse(pkg);
|
||||||
|
if (!version) {
|
||||||
|
throw `Could not find the toolkit version`;
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
};
|
||||||
|
|
||||||
main();
|
main();
|
||||||
8
scripts/make-github-release.sh
Executable file
8
scripts/make-github-release.sh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Exit script if a statement returns a non-true return value.
|
||||||
|
set -o errexit
|
||||||
|
# Use the error status of the first failure, rather than that of the last item in a pipeline.
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
node ./scripts/github/publishRelease.js
|
||||||
Reference in New Issue
Block a user