mirror of
https://github.com/actions/publish-action.git
synced 2025-04-21 10:12:26 +00:00
Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8a4b4f687b | ||
|
79dcc1330e | ||
|
ca6c5d975e | ||
|
2b67ec31c3 | ||
|
0f919ea818 | ||
|
f784495ce7 | ||
|
7ea110f150 | ||
|
e8908aab06 | ||
|
337dee4c7b | ||
|
740c66cdc2 | ||
|
e9810b12c0 | ||
|
e7e3b5daf5 | ||
|
3f069f6e86 | ||
|
9169aa7609 | ||
|
87579b14ff | ||
|
dca2315f75 | ||
|
7d07d33a07 | ||
|
112638faa9 | ||
|
98c01fe014 | ||
|
c79b33d62c | ||
|
64f299c71b |
6
.eslintignore
Normal file
6
.eslintignore
Normal file
@ -0,0 +1,6 @@
|
||||
# Ignore list
|
||||
/*
|
||||
|
||||
# Do not ignore these folders:
|
||||
!__tests__/
|
||||
!src/
|
51
.eslintrc.js
Normal file
51
.eslintrc.js
Normal file
@ -0,0 +1,51 @@
|
||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
||||
module.exports = {
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:eslint-plugin-jest/recommended',
|
||||
'eslint-config-prettier'
|
||||
],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint', 'eslint-plugin-node', 'eslint-plugin-jest'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-require-imports': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': [
|
||||
'error',
|
||||
{
|
||||
'ts-ignore': 'allow-with-description'
|
||||
}
|
||||
],
|
||||
'no-console': 'error',
|
||||
'yoda': 'error',
|
||||
'prefer-const': [
|
||||
'error',
|
||||
{
|
||||
destructuring: 'all'
|
||||
}
|
||||
],
|
||||
'no-control-regex': 'off',
|
||||
'no-constant-condition': ['error', {checkLoops: false}],
|
||||
'node/no-extraneous-import': 'error'
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['**/*{test,spec}.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'jest/no-standalone-expect': 'off',
|
||||
'jest/no-conditional-expect': 'off',
|
||||
'no-console': 'off',
|
||||
|
||||
}
|
||||
}
|
||||
],
|
||||
env: {
|
||||
node: true,
|
||||
es6: true,
|
||||
'jest/globals': true
|
||||
}
|
||||
};
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
* text=auto eol=lf
|
||||
.licenses/** -diff linguist-generated=true
|
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@ -1 +1 @@
|
||||
* @actions/virtual-environments-owners
|
||||
* @actions/setup-actions-team
|
||||
|
22
.github/dependabot.yml
vendored
Normal file
22
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
# Enable version updates for npm
|
||||
- package-ecosystem: 'npm'
|
||||
# Look for `package.json` and `lock` files in the `root` directory
|
||||
directory: '/'
|
||||
# Check the npm registry for updates every day (weekdays)
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
|
||||
# Enable version updates for GitHub Actions
|
||||
- package-ecosystem: 'github-actions'
|
||||
# Workflow files stored in the default location of `.github/workflows`
|
||||
# You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'weekly'
|
14
.github/workflows/basic-validation.yml
vendored
Normal file
14
.github/workflows/basic-validation.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
name: Basic validation
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
call-basic-validation:
|
||||
name: Basic validation
|
||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
||||
with:
|
||||
node-version: '20'
|
43
.github/workflows/check-dist.yml
vendored
43
.github/workflows/check-dist.yml
vendored
@ -1,8 +1,3 @@
|
||||
# `dist/index.js` is a special file in Actions.
|
||||
# When you reference an action with `uses:` in a workflow,
|
||||
# `index.js` is the code that will run.
|
||||
# For our project, we generate this file through a build process from other source files.
|
||||
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
|
||||
name: Check dist/
|
||||
|
||||
on:
|
||||
@ -17,36 +12,8 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
check-dist:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Rebuild the dist/ directory
|
||||
run: npm run build
|
||||
|
||||
- name: Compare the expected and actual dist/ directories
|
||||
run: |
|
||||
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
||||
echo "Detected uncommitted changes after build. See status below:"
|
||||
git diff
|
||||
exit 1
|
||||
fi
|
||||
id: diff
|
||||
|
||||
# If index.js was different than expected, upload the expected version as an artifact
|
||||
- uses: actions/upload-artifact@v2
|
||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
call-check-dist:
|
||||
name: Check dist/
|
||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
||||
with:
|
||||
node-version: '20'
|
||||
|
14
.github/workflows/codeql-analysis.yml
vendored
Normal file
14
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
name: CodeQL analysis
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
schedule:
|
||||
- cron: '0 3 * * 0'
|
||||
|
||||
jobs:
|
||||
call-codeQL-analysis:
|
||||
name: CodeQL analysis
|
||||
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
|
24
.github/workflows/licensed.yml
vendored
24
.github/workflows/licensed.yml
vendored
@ -1,20 +1,14 @@
|
||||
name: Licensed
|
||||
|
||||
on:
|
||||
push: {branches: main}
|
||||
pull_request: {branches: main}
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
name: Check licenses
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: npm ci
|
||||
- name: Install licensed
|
||||
run: |
|
||||
cd $RUNNER_TEMP
|
||||
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.4.4/licensed-3.4.4-linux-x64.tar.gz
|
||||
sudo tar -xzf licensed.tar.gz
|
||||
sudo mv licensed /usr/local/bin/licensed
|
||||
- run: licensed status
|
||||
call-licensed:
|
||||
name: Licensed
|
||||
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
|
||||
|
15
.github/workflows/release-new-action-version.yml
vendored
15
.github/workflows/release-new-action-version.yml
vendored
@ -1,4 +1,5 @@
|
||||
name: Release new action version
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
@ -24,11 +25,11 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Update the ${{ env.TAG_NAME }} tag
|
||||
id: update-major-tag
|
||||
uses: ./
|
||||
with:
|
||||
source-tag: ${{ env.TAG_NAME }}
|
||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||
- name: Update the ${{ env.TAG_NAME }} tag
|
||||
id: update-major-tag
|
||||
uses: ./
|
||||
with:
|
||||
source-tag: ${{ env.TAG_NAME }}
|
||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||
|
27
.github/workflows/test.yml
vendored
27
.github/workflows/test.yml
vendored
@ -1,27 +0,0 @@
|
||||
name: Tests
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set Node.JS
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Run tests
|
||||
run: npm run test
|
11
.github/workflows/update-config-files.yml
vendored
Normal file
11
.github/workflows/update-config-files.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
name: Update configuration files
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 3 * * 0'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
call-update-configuration-files:
|
||||
name: Update configuration files
|
||||
uses: actions/reusable-workflows/.github/workflows/update-config-files.yml@main
|
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/github.dep.yml
generated
BIN
.licenses/npm/@actions/github.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/http-client.dep.yml
generated
BIN
.licenses/npm/@actions/http-client.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@octokit/auth-token.dep.yml
generated
BIN
.licenses/npm/@octokit/auth-token.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/core.dep.yml
generated
BIN
.licenses/npm/@octokit/core.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/endpoint.dep.yml
generated
BIN
.licenses/npm/@octokit/endpoint.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/graphql.dep.yml
generated
BIN
.licenses/npm/@octokit/graphql.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/openapi-types.dep.yml
generated
BIN
.licenses/npm/@octokit/openapi-types.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/plugin-paginate-rest.dep.yml
generated
BIN
.licenses/npm/@octokit/plugin-paginate-rest.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@octokit/request-error.dep.yml
generated
BIN
.licenses/npm/@octokit/request-error.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/request.dep.yml
generated
BIN
.licenses/npm/@octokit/request.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@octokit/types.dep.yml
generated
BIN
.licenses/npm/@octokit/types.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/before-after-hook.dep.yml
generated
BIN
.licenses/npm/before-after-hook.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/is-plain-object.dep.yml
generated
BIN
.licenses/npm/is-plain-object.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/node-fetch.dep.yml
generated
BIN
.licenses/npm/node-fetch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/semver.dep.yml
generated
BIN
.licenses/npm/semver.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/universal-user-agent.dep.yml
generated
BIN
.licenses/npm/universal-user-agent.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/uuid.dep.yml
generated
Normal file
BIN
.licenses/npm/uuid.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
Binary file not shown.
7
.prettierignore
Normal file
7
.prettierignore
Normal file
@ -0,0 +1,7 @@
|
||||
# Ignore list
|
||||
/*
|
||||
|
||||
# Do not ignore these folders:
|
||||
!__tests__/
|
||||
!.github/
|
||||
!src/
|
11
.prettierrc.js
Normal file
11
.prettierrc.js
Normal file
@ -0,0 +1,11 @@
|
||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
||||
module.exports = {
|
||||
printWidth: 80,
|
||||
tabWidth: 2,
|
||||
useTabs: false,
|
||||
semi: true,
|
||||
singleQuote: true,
|
||||
trailingComma: 'none',
|
||||
bracketSpacing: false,
|
||||
arrowParens: 'avoid'
|
||||
};
|
11
README.md
11
README.md
@ -1,5 +1,7 @@
|
||||
# publish-action
|
||||
|
||||
[](https://github.com/actions/publish-action/actions/workflows/basic-validation.yml)
|
||||
|
||||
**Please note: this action is for internal usage only, issues are disabled and contributing PRs will not be reviewed. We also do not recommend this action for public or production usage while it is still in development.**
|
||||
|
||||
This action adds reliability to the new action versions publishing and handles the following cases:
|
||||
@ -18,6 +20,15 @@ Read more about action versioning notation in [action-versioning.md](https://git
|
||||
|
||||
To roll back a release in case of customer impact, start the workflow manually and specify the previous stable tag.
|
||||
|
||||
## Recommended permissions
|
||||
|
||||
When using the `publish-action` in your GitHub Actions workflow, it is recommended to set the following permissions to ensure proper functionality:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
contents: write # access to publish release
|
||||
```
|
||||
|
||||
## Conributions
|
||||
|
||||
We don't accept contributions until the action is ready for production.
|
||||
|
@ -1,39 +1,43 @@
|
||||
import * as github from "@actions/github";
|
||||
import * as apiUtils from "../src/api-utils";
|
||||
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");
|
||||
import prereleaseData from './data/pre-release.json';
|
||||
import releaseData from './data/release.json';
|
||||
|
||||
const token = "faketoken";
|
||||
const token = 'faketoken';
|
||||
const octokitClient = github.getOctokit(token);
|
||||
|
||||
let getReleaseSpy: jest.SpyInstance;
|
||||
|
||||
process.env.GITHUB_REPOSITORY = "test/repository";
|
||||
process.env.GITHUB_REPOSITORY = 'test/repository';
|
||||
|
||||
describe("validateIfReleaseIsPublished", () => {
|
||||
beforeEach(() => {
|
||||
getReleaseSpy = jest.spyOn(octokitClient.repos, "getReleaseByTag");
|
||||
});
|
||||
describe('validateIfReleaseIsPublished', () => {
|
||||
beforeEach(() => {
|
||||
getReleaseSpy = jest.spyOn(octokitClient.rest.repos, 'getReleaseByTag');
|
||||
});
|
||||
|
||||
it("throw if release is marked as pre-release", async () => {
|
||||
getReleaseSpy.mockReturnValue(prereleaseData);
|
||||
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"
|
||||
);
|
||||
});
|
||||
expect.assertions(1);
|
||||
await expect(
|
||||
apiUtils.validateIfReleaseIsPublished('v1.0.0', octokitClient)
|
||||
).rejects.toThrow(
|
||||
"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);
|
||||
it('validate that release is published', async () => {
|
||||
getReleaseSpy.mockReturnValue(releaseData);
|
||||
|
||||
expect.assertions(1);
|
||||
await expect(apiUtils.validateIfReleaseIsPublished("v1.1.0", octokitClient)).resolves.not.toThrow();
|
||||
});
|
||||
expect.assertions(1);
|
||||
await expect(
|
||||
apiUtils.validateIfReleaseIsPublished('v1.1.0', octokitClient)
|
||||
).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
});
|
@ -1,69 +1,93 @@
|
||||
import * as versionUtils from "../src/version-utils";
|
||||
import * as versionUtils from '../src/version-utils';
|
||||
import stableSemver from './data/stable-semver.json';
|
||||
import stableBuildSemver from './data/stable-build-semver.json';
|
||||
import prereleaseSemver from './data/prerelease-semver.json';
|
||||
import prereleaseBuildSemver from './data/prerelease-build-semver.json';
|
||||
|
||||
describe("isStableSemverVersion", () => {
|
||||
it("validate if a version is stable", () => {
|
||||
const semverVersion = require("./data/stable-semver.json");
|
||||
expect(versionUtils.isStableSemverVersion(semverVersion)).toBeTruthy();
|
||||
});
|
||||
describe('isStableSemverVersion', () => {
|
||||
it('validate if a version is stable', () => {
|
||||
expect(
|
||||
versionUtils.isStableSemverVersion(stableSemver as any)
|
||||
).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 version with build metadata is stable', () => {
|
||||
expect(
|
||||
versionUtils.isStableSemverVersion(stableBuildSemver as any)
|
||||
).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 is not stable', () => {
|
||||
expect(
|
||||
versionUtils.isStableSemverVersion(prereleaseSemver as any)
|
||||
).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();
|
||||
});
|
||||
it('validate if a pre-release version with build metadata is not stable', () => {
|
||||
expect(
|
||||
versionUtils.isStableSemverVersion(prereleaseBuildSemver as any)
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateSemverVersionFromTag", () => {
|
||||
it("validate a tag containing an valid semantic version", () => {
|
||||
expect(() => versionUtils.validateSemverVersionFromTag("1.0.0")).not.toThrow();
|
||||
});
|
||||
describe('validateSemverVersionFromTag', () => {
|
||||
it('validate a tag containing a 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 a 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('validate a tag containing a 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 invalid semantic version', () => {
|
||||
expect(() =>
|
||||
versionUtils.validateSemverVersionFromTag('1.0.0invalid')
|
||||
).toThrow(
|
||||
"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 a valid unstable semantic version', () => {
|
||||
expect(() =>
|
||||
versionUtils.validateSemverVersionFromTag('v1.0.0-beta.1')
|
||||
).toThrow(
|
||||
'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"
|
||||
);
|
||||
});
|
||||
it('throw when a tag contains a valid unstable semantic version with build metadata', () => {
|
||||
expect(() =>
|
||||
versionUtils.validateSemverVersionFromTag('v1.0.0-beta.1+20130313144700')
|
||||
).toThrow(
|
||||
'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);
|
||||
});
|
||||
});
|
||||
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);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
@ -13,5 +13,5 @@ outputs:
|
||||
major-tag:
|
||||
description: 'The major version tag that has been updated (created). Examples: v1, 1'
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
|
34382
dist/index.js
vendored
34382
dist/index.js
vendored
File diff suppressed because one or more lines are too long
11265
package-lock.json
generated
11265
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,11 +1,15 @@
|
||||
{
|
||||
"name": "publish-action",
|
||||
"version": "0.1.0",
|
||||
"version": "0.3.0",
|
||||
"description": "Update the major version tag (v1, v2, etc.) to point to the specified tag",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build",
|
||||
"test": "jest"
|
||||
"test": "jest",
|
||||
"format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write \"**/*.{ts,yml,yaml}\"",
|
||||
"format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check \"**/*.{ts,yml,yaml}\"",
|
||||
"lint": "eslint --config ./.eslintrc.js \"**/*.ts\"",
|
||||
"lint:fix": "eslint --config ./.eslintrc.js \"**/*.ts\" --fix"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -23,17 +27,24 @@
|
||||
"homepage": "https://github.com/actions/publish-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.7",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
"@actions/github": "^4.0.0",
|
||||
"semver": "^7.3.5"
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/http-client": "^2.2.0",
|
||||
"semver": "^7.5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/jest": "^29.5.10",
|
||||
"@types/semver": "^7.3.6",
|
||||
"@vercel/ncc": "^0.28.5",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.5",
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.2.4"
|
||||
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
||||
"@typescript-eslint/parser": "^6.12.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.35.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-jest": "^27.2.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"prettier": "^3.1.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.3.2"
|
||||
}
|
||||
}
|
||||
|
173
src/api-utils.ts
173
src/api-utils.ts
@ -1,114 +1,121 @@
|
||||
import * as core from '@actions/core';
|
||||
import { context } from '@actions/github';
|
||||
import { GitHub } from '@actions/github/lib/utils';
|
||||
import { HttpClient } from '@actions/http-client';
|
||||
import {context} from '@actions/github';
|
||||
import {GitHub} from '@actions/github/lib/utils';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
|
||||
interface GitRef {
|
||||
ref: string;
|
||||
node_id: string;
|
||||
ref: string;
|
||||
node_id: string;
|
||||
url: string;
|
||||
object: {
|
||||
type: string;
|
||||
sha: string;
|
||||
url: string;
|
||||
object: {
|
||||
type: string;
|
||||
sha: string;
|
||||
url: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface ErrorStatus extends Error {
|
||||
status?: number;
|
||||
}
|
||||
|
||||
async function findTag(
|
||||
tag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
tag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
): Promise<GitRef | null> {
|
||||
try {
|
||||
const { data: foundTag } = await octokitClient.git.getRef({
|
||||
...context.repo,
|
||||
ref: `tags/${tag}`
|
||||
});
|
||||
try {
|
||||
const {data: foundTag} = await octokitClient.rest.git.getRef({
|
||||
...context.repo,
|
||||
ref: `tags/${tag}`
|
||||
});
|
||||
|
||||
return foundTag;
|
||||
} catch (err) {
|
||||
if (err.status === 404) {
|
||||
return null;
|
||||
} else {
|
||||
throw new Error(
|
||||
`Retrieving refs failed with the following error: ${err}`
|
||||
);
|
||||
}
|
||||
return foundTag;
|
||||
} catch (err) {
|
||||
if ((err as ErrorStatus).status === 404) {
|
||||
return null;
|
||||
} else {
|
||||
throw new Error(
|
||||
`Retrieving refs failed with the following error: ${err}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getTagSHA(
|
||||
tag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
tag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
): Promise<string> {
|
||||
const foundTag = await findTag(tag, octokitClient);
|
||||
if (!foundTag) {
|
||||
throw new Error(
|
||||
`The '${tag}' tag does not exist in the remote repository`
|
||||
);
|
||||
}
|
||||
const foundTag = await findTag(tag, octokitClient);
|
||||
if (!foundTag) {
|
||||
throw new Error(`The '${tag}' tag does not exist in the remote repository`);
|
||||
}
|
||||
|
||||
return foundTag.object.sha;
|
||||
return foundTag.object.sha;
|
||||
}
|
||||
|
||||
export async function validateIfReleaseIsPublished(
|
||||
tag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
tag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
): Promise<void> {
|
||||
try {
|
||||
const { data: foundRelease } = await octokitClient.repos.getReleaseByTag({
|
||||
...context.repo,
|
||||
tag,
|
||||
});
|
||||
try {
|
||||
const {data: foundRelease} = await octokitClient.rest.repos.getReleaseByTag(
|
||||
{
|
||||
...context.repo,
|
||||
tag
|
||||
}
|
||||
);
|
||||
|
||||
if (foundRelease.prerelease) {
|
||||
throw new Error(
|
||||
`The '${foundRelease.name}' release is marked as pre-release. Updating tags for pre-release is not supported`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.status === 404) {
|
||||
throw new Error(
|
||||
`No GitHub release found for the ${tag} tag`
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Retrieving releases failed with the following error: ${err}`
|
||||
);
|
||||
}
|
||||
if (foundRelease.prerelease) {
|
||||
throw new Error(
|
||||
`The '${foundRelease.name}' release is marked as pre-release. Updating tags for pre-release is not supported`
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
if ((err as ErrorStatus).status === 404) {
|
||||
throw new Error(`No GitHub release found for the ${tag} tag`);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Retrieving releases failed with the following error: ${err}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateTag(
|
||||
sourceTag: string,
|
||||
targetTag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
sourceTag: string,
|
||||
targetTag: string,
|
||||
octokitClient: InstanceType<typeof GitHub>
|
||||
): Promise<void> {
|
||||
const sourceTagSHA = await getTagSHA(sourceTag, octokitClient);
|
||||
const foundTargetTag = await findTag(targetTag, octokitClient);
|
||||
const refName = `tags/${targetTag}`;
|
||||
const sourceTagSHA = await getTagSHA(sourceTag, octokitClient);
|
||||
const foundTargetTag = await findTag(targetTag, octokitClient);
|
||||
const refName = `tags/${targetTag}`;
|
||||
|
||||
if (foundTargetTag) {
|
||||
core.info(`Updating the '${targetTag}' tag to point to the '${sourceTag}' tag`);
|
||||
if (foundTargetTag) {
|
||||
core.info(
|
||||
`Updating the '${targetTag}' tag to point to the '${sourceTag}' tag`
|
||||
);
|
||||
|
||||
await octokitClient.git.updateRef({
|
||||
...context.repo,
|
||||
ref: refName,
|
||||
sha: sourceTagSHA,
|
||||
force: true
|
||||
});
|
||||
} else {
|
||||
core.info(`Creating the '${targetTag}' tag from the '${sourceTag}' tag`);
|
||||
await octokitClient.rest.git.updateRef({
|
||||
...context.repo,
|
||||
ref: refName,
|
||||
sha: sourceTagSHA,
|
||||
force: true
|
||||
});
|
||||
} else {
|
||||
core.info(`Creating the '${targetTag}' tag from the '${sourceTag}' tag`);
|
||||
|
||||
await octokitClient.git.createRef({
|
||||
...context.repo,
|
||||
ref: `refs/${refName}`,
|
||||
sha: sourceTagSHA
|
||||
});
|
||||
}
|
||||
await octokitClient.rest.git.createRef({
|
||||
...context.repo,
|
||||
ref: `refs/${refName}`,
|
||||
sha: sourceTagSHA
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function postMessageToSlack(slackWebhook: string, message: string): Promise<void> {
|
||||
const jsonData = {text: message}
|
||||
const http = new HttpClient();
|
||||
await http.postJson(slackWebhook, jsonData);
|
||||
export async function postMessageToSlack(
|
||||
slackWebhook: string,
|
||||
message: string
|
||||
): Promise<void> {
|
||||
const jsonData = {text: message};
|
||||
const http = new HttpClient();
|
||||
await http.postJson(slackWebhook, jsonData);
|
||||
}
|
59
src/main.ts
59
src/main.ts
@ -1,40 +1,49 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import { context } from '@actions/github';
|
||||
import { updateTag, validateIfReleaseIsPublished, postMessageToSlack } from './api-utils';
|
||||
import { validateSemverVersionFromTag, getMajorTagFromFullTag } from './version-utils';
|
||||
import {context} from '@actions/github';
|
||||
import {
|
||||
updateTag,
|
||||
validateIfReleaseIsPublished,
|
||||
postMessageToSlack
|
||||
} from './api-utils';
|
||||
import {
|
||||
validateSemverVersionFromTag,
|
||||
getMajorTagFromFullTag
|
||||
} from './version-utils';
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const token = core.getInput('token');
|
||||
const octokitClient = github.getOctokit(token);
|
||||
const sourceTagName = core.getInput('source-tag');
|
||||
try {
|
||||
const token = core.getInput('token');
|
||||
const octokitClient = github.getOctokit(token);
|
||||
const sourceTagName = core.getInput('source-tag');
|
||||
|
||||
validateSemverVersionFromTag(sourceTagName);
|
||||
validateSemverVersionFromTag(sourceTagName);
|
||||
|
||||
await validateIfReleaseIsPublished(sourceTagName, octokitClient);
|
||||
await validateIfReleaseIsPublished(sourceTagName, octokitClient);
|
||||
|
||||
const majorTag = getMajorTagFromFullTag(sourceTagName);
|
||||
await updateTag(sourceTagName, majorTag, octokitClient);
|
||||
const majorTag = getMajorTagFromFullTag(sourceTagName);
|
||||
await updateTag(sourceTagName, majorTag, octokitClient);
|
||||
|
||||
core.setOutput('major-tag', majorTag);
|
||||
core.info(`The '${majorTag}' major tag now points to the '${sourceTagName}' tag`);
|
||||
core.setOutput('major-tag', majorTag);
|
||||
core.info(
|
||||
`The '${majorTag}' major tag now points to the '${sourceTagName}' tag`
|
||||
);
|
||||
|
||||
const slackMessage = `The ${majorTag} tag has been successfully updated for the ${context.repo.repo} action to include changes from the ${sourceTagName}`;
|
||||
await reportStatusToSlack(slackMessage);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
const slackMessage = `The ${majorTag} tag has been successfully updated for the ${context.repo.repo} action to include changes from ${sourceTagName}`;
|
||||
await reportStatusToSlack(slackMessage);
|
||||
} catch (error) {
|
||||
core.setFailed((error as Error).message);
|
||||
|
||||
const slackMessage = `Failed to update a major tag for the ${context.repo.repo} action`;
|
||||
await reportStatusToSlack(slackMessage);
|
||||
}
|
||||
};
|
||||
const slackMessage = `Failed to update a major tag for the ${context.repo.repo} action`;
|
||||
await reportStatusToSlack(slackMessage);
|
||||
}
|
||||
}
|
||||
|
||||
async function reportStatusToSlack(message: string): Promise<void> {
|
||||
const slackWebhook = core.getInput('slack-webhook');
|
||||
if (slackWebhook) {
|
||||
await postMessageToSlack(slackWebhook, message);
|
||||
}
|
||||
const slackWebhook = core.getInput('slack-webhook');
|
||||
if (slackWebhook) {
|
||||
await postMessageToSlack(slackWebhook, message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
@ -2,24 +2,24 @@ import semverParse from 'semver/functions/parse';
|
||||
import SemVer from 'semver/classes/semver';
|
||||
|
||||
export function isStableSemverVersion(version: SemVer): boolean {
|
||||
return version.prerelease.length === 0
|
||||
return version.prerelease.length === 0;
|
||||
}
|
||||
|
||||
export function getMajorTagFromFullTag(fullTag: string): string {
|
||||
return fullTag.split('.')[0];
|
||||
return fullTag.split('.')[0];
|
||||
}
|
||||
|
||||
export function validateSemverVersionFromTag(tag: string): void {
|
||||
const semverVersion = semverParse(tag);
|
||||
if (!semverVersion) {
|
||||
throw new Error(
|
||||
`The '${tag}' doesn't satisfy semantic versioning specification`
|
||||
);
|
||||
}
|
||||
const semverVersion = semverParse(tag);
|
||||
if (!semverVersion) {
|
||||
throw new Error(
|
||||
`The '${tag}' doesn't satisfy semantic versioning specification`
|
||||
);
|
||||
}
|
||||
|
||||
if (!isStableSemverVersion(semverVersion)) {
|
||||
throw new Error(
|
||||
'It is not allowed to specify pre-release version to update the major tag'
|
||||
);
|
||||
}
|
||||
if (!isStableSemverVersion(semverVersion)) {
|
||||
throw new Error(
|
||||
'It is not allowed to specify pre-release version to update the major tag'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
|
Loading…
Reference in New Issue
Block a user