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

how to add .zip file as asset from a pull request that generates a new release tag #745

Open
daniloab opened this issue Feb 9, 2022 · 2 comments

Comments

@daniloab
Copy link

daniloab commented Feb 9, 2022

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?

@steveukx
Copy link
Owner

steveukx commented Feb 9, 2022

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

@steveukx steveukx added the more-info-needed More information is required in order to investigate label Feb 9, 2022
@daniloab
Copy link
Author

daniloab commented Feb 9, 2022

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 @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?

@no-response no-response bot removed the more-info-needed More information is required in order to investigate label Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants