how to add .zip file as asset from a pull request that generates a new release tag
Hi, there.
I have a script that uses the git-js, which is an awesome lib, to generate a new pull request with a new tag for a release.
Today I can add files to this pull request and also generate a new tag release with it.
I want to know how can I add a .zip file as an asset to this release. This is how my code is working today:
await git().checkout(['-B', branchName]);
await git().add([
'package.json',
'CHANGELOG.md',
myzipfile.zip,
'-f',
]);
await git().commit(`build(change-log): ${tag}`, [], '-n');
await git().addAnnotatedTag(`${tag}`, `build(tag): ${tag}`);
await git().push(['--follow-tags', '-u', 'origin', branchName]);
branchName: variable that explains itself tag: tag of the new release
Inside this workflow, I generate a .zip file and I want to add it as an asset to this release tag.
How can I do it?
Hi, if you are using GitHub as your remote, any tag is available as github.com/user/repo/tags and automatically have a downloadable zip/tar of the content of the repo in that tag. (eg: https://github.com/steveukx/git-js/tags)
As best I am aware, you would need to use the Github APIs - for example in the package https://www.npmjs.com/package/@octokit/rest
Hi, if you are using
GitHubas your remote, any tag is available asgithub.com/user/repo/tagsand automatically have a downloadable zip/tar of the content of the repo in that tag. (eg: https://github.com/steveukx/git-js/tags)As best I am aware, you would need to use the Github APIs - for example in the package https://www.npmjs.com/package/@octokit/rest
Hi @steveukx Im already using the octokit to open the pull request after with this function after prepare it with the git() functions:
const createPullRequest = async (branchName, tag) => {
if (!process.env.GITHUB_TOKEN) {
return;
}
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
const now = moment().format('YYYY-MM-DD');
// https://octokit.github.io/rest.js/#api-Repos-getReleases
// https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
const latestReleases = await octokit.repos.listReleases({
owner,
repo,
per_page: 1,
});
const latestReleaseTag =
latestReleases && latestReleases.data && latestReleases.data.length
? latestReleases.data[0].tag_name
: 'master';
await octokit.pulls.create({
owner,
repo,
title: `Deploy Production - ${tag} - ${now}`,
head: branchName,
base: 'master',
body: `https://github.com/${owner}/${repo}/compare/${latestReleaseTag}...master`,
});
};
I want to add a specific .zip file to the assets when the tag is released. So, this is responsible for octokit not from git-js?