mirror of
https://github.com/actions/publish-action.git
synced 2025-06-24 11:51:09 +02:00
Implement the "publish-action" action
This commit is contained in:
39
__tests__/api-utils.test.ts
Normal file
39
__tests__/api-utils.test.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import * as github from "@actions/github";
|
||||
import * as apiUtils from "../src/api-utils";
|
||||
|
||||
const prereleaseData = require("./data/pre-release.json");
|
||||
const releaseData = require("./data/release.json");
|
||||
|
||||
const token = "faketoken";
|
||||
const octokitClient = github.getOctokit(token);
|
||||
|
||||
let getReleaseSpy: jest.SpyInstance;
|
||||
|
||||
process.env.GITHUB_REPOSITORY = "test/repository";
|
||||
|
||||
describe("validateIfReleaseIsPublished", () => {
|
||||
beforeEach(() => {
|
||||
getReleaseSpy = jest.spyOn(octokitClient.repos, "getReleaseByTag");
|
||||
});
|
||||
|
||||
it("throw if release is marked as pre-release", async () => {
|
||||
getReleaseSpy.mockReturnValue(prereleaseData);
|
||||
|
||||
expect.assertions(1);
|
||||
await expect(apiUtils.validateIfReleaseIsPublished("v1.0.0", octokitClient)).rejects.toThrowError(
|
||||
"The 'v1.0.0' release is marked as pre-release. Updating tags for pre-release is not supported"
|
||||
);
|
||||
});
|
||||
|
||||
it("validate that release is published", async () => {
|
||||
getReleaseSpy.mockReturnValue(releaseData);
|
||||
|
||||
expect.assertions(1);
|
||||
await expect(apiUtils.validateIfReleaseIsPublished("v1.1.0", octokitClient)).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
});
|
14
__tests__/data/pre-release.json
Normal file
14
__tests__/data/pre-release.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"data": {
|
||||
"id": 1,
|
||||
"node_id": "MDc6UmVsZWFzZTE=",
|
||||
"tag_name": "v1.0.0",
|
||||
"target_commitish": "main",
|
||||
"name": "v1.0.0",
|
||||
"body": "Description of the release",
|
||||
"draft": false,
|
||||
"prerelease": true,
|
||||
"created_at": "2013-02-27T19:35:32Z",
|
||||
"published_at": "2013-02-27T19:35:32Z"
|
||||
}
|
||||
}
|
12
__tests__/data/prerelease-build-semver.json
Normal file
12
__tests__/data/prerelease-build-semver.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"options": {},
|
||||
"loose": false,
|
||||
"includePrerelease": false,
|
||||
"raw": "v1.0.0-beta.1+20130313144700",
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"patch": 0,
|
||||
"prerelease": [ "beta", 1 ],
|
||||
"build": [ "20130313144700" ],
|
||||
"version": "1.0.0-beta.1"
|
||||
}
|
12
__tests__/data/prerelease-semver.json
Normal file
12
__tests__/data/prerelease-semver.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"options": {},
|
||||
"loose": false,
|
||||
"includePrerelease": false,
|
||||
"raw": "v1.0.0-beta.1",
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"patch": 0,
|
||||
"prerelease": [ "beta", 1 ],
|
||||
"build": [],
|
||||
"version": "1.0.0-beta.1"
|
||||
}
|
14
__tests__/data/release.json
Normal file
14
__tests__/data/release.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"data": {
|
||||
"id": 1,
|
||||
"node_id": "MDc6UmVsZWFzZTE=",
|
||||
"tag_name": "v1.1.0",
|
||||
"target_commitish": "main",
|
||||
"name": "v1.1.0",
|
||||
"body": "Description of the release",
|
||||
"draft": false,
|
||||
"prerelease": false,
|
||||
"created_at": "2013-02-27T19:35:32Z",
|
||||
"published_at": "2013-02-27T19:35:32Z"
|
||||
}
|
||||
}
|
12
__tests__/data/stable-build-semver.json
Normal file
12
__tests__/data/stable-build-semver.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"options": {},
|
||||
"loose": false,
|
||||
"includePrerelease": false,
|
||||
"raw": "1.0.0+20130313144700",
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"patch": 0,
|
||||
"prerelease": [],
|
||||
"build": [ "20130313144700" ],
|
||||
"version": "1.0.0"
|
||||
}
|
12
__tests__/data/stable-semver.json
Normal file
12
__tests__/data/stable-semver.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"options": {},
|
||||
"loose": false,
|
||||
"includePrerelease": false,
|
||||
"raw": "v1.0.0",
|
||||
"major": 1,
|
||||
"minor": 0,
|
||||
"patch": 0,
|
||||
"prerelease": [],
|
||||
"build": [],
|
||||
"version": "1.0.0"
|
||||
}
|
69
__tests__/version-utils.test.ts
Normal file
69
__tests__/version-utils.test.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import * as versionUtils from "../src/version-utils";
|
||||
|
||||
describe("isStableSemverVersion", () => {
|
||||
it("validate if a version is stable", () => {
|
||||
const semverVersion = require("./data/stable-semver.json");
|
||||
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("validate if a version with build metadata is stable", () => {
|
||||
const semverVersion = require("./data/stable-build-semver.json");
|
||||
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("validate if a pre-release version is not stable", () => {
|
||||
const semverVersion = require("./data/prerelease-semver.json");
|
||||
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeFalsy();
|
||||
});
|
||||
|
||||
it("validate if a pre-release version with build metadata is not stable", () => {
|
||||
const semverVersion = require("./data/prerelease-build-semver.json");
|
||||
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateSemverVersionFromTag", () => {
|
||||
it("validate a tag containing an valid semantic version", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("1.0.0")).not.toThrow();
|
||||
});
|
||||
|
||||
it("validate a tag containing an valid semantic version with 'v' prefix", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0")).not.toThrow();
|
||||
});
|
||||
|
||||
it("validate a tag containing an valid semantic version with build metadata", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0+20130313144700")).not.toThrow();
|
||||
});
|
||||
|
||||
it("throw when a tag contains an invalid semantic version", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("1.0.0invalid")).toThrowError(
|
||||
"The '1.0.0invalid' doesn't satisfy semantic versioning specification"
|
||||
);
|
||||
});
|
||||
|
||||
it("throw when a tag contains an valid unstable semantic version", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0-beta.1")).toThrowError(
|
||||
"It is not allowed to specify pre-release version to update the major tag"
|
||||
);
|
||||
});
|
||||
|
||||
it("throw when a tag contains an valid unstable semantic version with build metadata", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("v1.0.0-beta.1+20130313144700")).toThrowError(
|
||||
"It is not allowed to specify pre-release version to update the major tag"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getMajorTagFromFullTag", () => {
|
||||
describe("get a valid major tag from full tag", () => {
|
||||
it.each([
|
||||
["1.0.0", "1"],
|
||||
["v1.0.0", "v1"],
|
||||
["v1.0.0-beta.1", "v1"],
|
||||
["v1.0.0+20130313144700", "v1"],
|
||||
] as [string, string][])("%s -> %s", (sourceTag: string, expectedMajorTag: string) => {
|
||||
const resultantMajorTag = versionUtils.getMajorTagFromFullTag(sourceTag);
|
||||
expect(resultantMajorTag).toBe(expectedMajorTag);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user