fix: fetch all release branches on CI
This commit is contained in:
+24
-7
@@ -1,4 +1,4 @@
|
||||
const {trimStart, matches, pick, memoize} = require('lodash');
|
||||
const {matches, pick, memoize} = require('lodash');
|
||||
const gitLogParser = require('git-log-parser');
|
||||
const getStream = require('get-stream');
|
||||
const execa = require('execa');
|
||||
@@ -63,9 +63,9 @@ async function getCommits(from, to, execaOpts) {
|
||||
* @throws {Error} If the `git` command fails.
|
||||
*/
|
||||
async function getBranches(execaOpts) {
|
||||
return (await execa.stdout('git', ['branch', '--list', '--no-color'], execaOpts))
|
||||
return (await execa.stdout('git', ['ls-remote', '--heads', 'origin'], execaOpts))
|
||||
.split('\n')
|
||||
.map(branch => trimStart(branch, '*').trim())
|
||||
.map(branch => branch.match(/^.+refs\/heads\/(.+)$/)[1])
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
@@ -126,13 +126,30 @@ async function isRefExists(ref, execaOpts) {
|
||||
/**
|
||||
* Unshallow the git repository if necessary and fetch all the tags.
|
||||
*
|
||||
* @param {String} branch The repository branch to fetch.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*/
|
||||
async function fetch(execaOpts) {
|
||||
async function fetch(branch, execaOpts) {
|
||||
const isLocalExists =
|
||||
(await execa('git', ['rev-parse', '--verify', branch], {...execaOpts, reject: false})).code === 0;
|
||||
|
||||
try {
|
||||
await execa('git', ['fetch', '--unshallow', '--tags'], execaOpts);
|
||||
await execa(
|
||||
'git',
|
||||
[
|
||||
'fetch',
|
||||
'--unshallow',
|
||||
'--tags',
|
||||
...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||
],
|
||||
execaOpts
|
||||
);
|
||||
} catch (error) {
|
||||
await execa('git', ['fetch', '--tags'], execaOpts);
|
||||
await execa(
|
||||
'git',
|
||||
['fetch', '--tags', ...(isLocalExists ? [] : ['origin', `+refs/heads/${branch}:refs/heads/${branch}`])],
|
||||
execaOpts
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +198,7 @@ async function isGitRepo(execaOpts) {
|
||||
* Verify the write access authorization to remote repository with push dry-run.
|
||||
*
|
||||
* @param {String} repositoryUrl The remote repository URL.
|
||||
* @param {String} branch The repositoru branch for which to verify write access.
|
||||
* @param {String} branch The repository branch for which to verify write access.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @throws {Error} if not authorized to push.
|
||||
|
||||
Reference in New Issue
Block a user