added target-branch test
This commit is contained in:
parent
82dea4473f
commit
13fadb9dcc
|
@ -131,6 +131,31 @@ suites:
|
||||||
expected:
|
expected:
|
||||||
version: 4.1.2
|
version: 4.1.2
|
||||||
tag: v4.1.2
|
tag: v4.1.2
|
||||||
|
- name: target-branch
|
||||||
|
yaml:
|
||||||
|
name: Bump Version (Target Branch)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
jobs:
|
||||||
|
bump-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: git branch other-branch
|
||||||
|
- id: version-bump
|
||||||
|
uses: ./action
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
target-branch: other-branch
|
||||||
|
tests:
|
||||||
|
- message: no keywords
|
||||||
|
expected:
|
||||||
|
version: 4.1.3
|
||||||
|
branch: other-branch
|
||||||
|
|
||||||
actionFiles:
|
actionFiles:
|
||||||
- index.js
|
- index.js
|
||||||
- Dockerfile
|
- Dockerfile
|
||||||
|
|
|
@ -4,17 +4,4 @@ function git(options, ...params) {
|
||||||
return exec('git', options, ...params);
|
return exec('git', options, ...params);
|
||||||
}
|
}
|
||||||
|
|
||||||
let firstCommit = true;
|
module.exports = git;
|
||||||
function push() {
|
|
||||||
if (firstCommit) {
|
|
||||||
firstCommit = false;
|
|
||||||
return git('push', '--force', '--set-upstream', 'origin', 'main');
|
|
||||||
} else {
|
|
||||||
return git('push');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
push,
|
|
||||||
default: git,
|
|
||||||
};
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ const { readFileSync } = require('fs');
|
||||||
const { writeFile, readFile, mkdir } = require('fs/promises');
|
const { writeFile, readFile, mkdir } = require('fs/promises');
|
||||||
const { resolve, join } = require('path');
|
const { resolve, join } = require('path');
|
||||||
const { cwd } = require('process');
|
const { cwd } = require('process');
|
||||||
const { default: git, push: gitPush } = require('./git');
|
const git = require('./git');
|
||||||
const { getMostRecentWorkflowRun, getWorkflowRun } = require('./actionsApi');
|
const { getMostRecentWorkflowRun, getWorkflowRun } = require('./actionsApi');
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
@ -29,12 +29,11 @@ config.suites.forEach((suite) => {
|
||||||
await git('commit', '--message', commit.message);
|
await git('commit', '--message', commit.message);
|
||||||
|
|
||||||
const mostRecentDate = await getMostRecentWorkflowRunDate();
|
const mostRecentDate = await getMostRecentWorkflowRunDate();
|
||||||
await gitPush();
|
await git('push');
|
||||||
|
|
||||||
const completedRun = await getCompletedRunAfter(mostRecentDate);
|
const completedRun = await getCompletedRunAfter(mostRecentDate);
|
||||||
expect(completedRun.conclusion).toBe('success');
|
expect(completedRun.conclusion).toBe('success');
|
||||||
|
|
||||||
await git('pull');
|
|
||||||
await assertExpectation(commit.expected);
|
await assertExpectation(commit.expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -60,7 +59,7 @@ async function generateReadMe(commit, suiteYaml) {
|
||||||
'## Message',
|
'## Message',
|
||||||
commit.message,
|
commit.message,
|
||||||
'## Expectation',
|
'## Expectation',
|
||||||
`**Version:** ${commit.expected.version}`,
|
generateExpectationText(commit.expected),
|
||||||
].join('\n');
|
].join('\n');
|
||||||
await writeFile(join(cwd(), readmePath), readMeContents);
|
await writeFile(join(cwd(), readmePath), readMeContents);
|
||||||
await git('add', readmePath);
|
await git('add', readmePath);
|
||||||
|
@ -100,13 +99,32 @@ async function getMostRecentWorkflowRunDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertExpectation({ version: expectedVersion, tag: expectedTag }) {
|
function generateExpectationText({ version: expectedVersion, tag: expectedTag, branch: expectedBranch }) {
|
||||||
|
const results = [`- **Version:** ${expectedVersion}`];
|
||||||
|
if (expectedTag) {
|
||||||
|
results.push(`- **Tag:** ${expectedTag}`);
|
||||||
|
}
|
||||||
|
if (expectedBranch) {
|
||||||
|
results.push(`- **Branch:** ${expectedBranch}`);
|
||||||
|
}
|
||||||
|
return results.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function assertExpectation({ version: expectedVersion, tag: expectedTag, branch: expectedBranch }) {
|
||||||
if (expectedTag === undefined) {
|
if (expectedTag === undefined) {
|
||||||
expectedTag = expectedVersion;
|
expectedTag = expectedVersion;
|
||||||
}
|
}
|
||||||
|
if (expectedBranch) {
|
||||||
|
await git('fetch', 'origin', expectedBranch);
|
||||||
|
await git('checkout', expectedBranch);
|
||||||
|
}
|
||||||
|
await git('pull');
|
||||||
const [packageVersion, latestTag] = await Promise.all([getPackageJsonVersion(), getLatestTag()]);
|
const [packageVersion, latestTag] = await Promise.all([getPackageJsonVersion(), getLatestTag()]);
|
||||||
expect(packageVersion).toBe(expectedVersion);
|
expect(packageVersion).toBe(expectedVersion);
|
||||||
expect(latestTag).toBe(expectedTag);
|
expect(latestTag).toBe(expectedTag);
|
||||||
|
if (expectedBranch) {
|
||||||
|
await git('checkout', 'main');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPackageJsonVersion() {
|
async function getPackageJsonVersion() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ const { rm, mkdir, copyFile, stat } = require('fs/promises');
|
||||||
const { chdir, cwd } = require('process');
|
const { chdir, cwd } = require('process');
|
||||||
const { resolve, join, dirname } = require('path');
|
const { resolve, join, dirname } = require('path');
|
||||||
const exec = require('./exec');
|
const exec = require('./exec');
|
||||||
const { default: git } = require('./git');
|
const git = require('./git');
|
||||||
const glob = require('tiny-glob');
|
const glob = require('tiny-glob');
|
||||||
const { clearWorkflowRuns } = require('./actionsApi');
|
const { clearWorkflowRuns } = require('./actionsApi');
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ module.exports = async function setupTestRepo(actionFileGlobPaths) {
|
||||||
await git('config', 'user.email', 'gh-action-bump-version-test@users.noreply.github.com');
|
await git('config', 'user.email', 'gh-action-bump-version-test@users.noreply.github.com');
|
||||||
await git('add', '.');
|
await git('add', '.');
|
||||||
await git('commit', '--message', 'initial commit (version 1.0.0)');
|
await git('commit', '--message', 'initial commit (version 1.0.0)');
|
||||||
await deleteTags();
|
await git('push', '--force', '--set-upstream', 'origin', 'main');
|
||||||
|
await deleteTagsAndBranches();
|
||||||
};
|
};
|
||||||
|
|
||||||
function createNpmPackage() {
|
function createNpmPackage() {
|
||||||
|
@ -57,13 +58,13 @@ async function copyActionFiles(globPaths) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteTags() {
|
async function deleteTagsAndBranches() {
|
||||||
const listTagsResult = await git({ suppressOutput: true }, 'ls-remote', '--tags', 'origin');
|
const listResult = await git({ suppressOutput: true }, 'ls-remote', '--tags', '--heads', 'origin');
|
||||||
if (listTagsResult.stdout) {
|
if (listResult.stdout) {
|
||||||
const lines = listTagsResult.stdout.split('\n');
|
const lines = listResult.stdout.split('\n');
|
||||||
const tags = lines.map((line) => line.split('\t')[1]);
|
const refs = lines.map((line) => line.split('\t')[1]).filter((ref) => ref !== 'refs/heads/main');
|
||||||
for (const tag of tags) {
|
if (refs.length > 0) {
|
||||||
await git('push', 'origin', '--delete', tag);
|
await git('push', 'origin', '--delete', ...refs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue