Skip to content

Commit 795acbb

Browse files
feat: Build for release
1 parent 6ef4cde commit 795acbb

File tree

379 files changed

+58897
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

379 files changed

+58897
-34
lines changed

README.md

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,29 @@ Once you publish the release, this action will automatically
1313
1. Change release tag
1414

1515
## Installation
16-
.github/workflows/release.yml
17-
```yaml
18-
on: release
19-
name: Release
20-
jobs:
21-
release:
22-
name: Release GitHub Actions
23-
runs-on: ubuntu-latest
24-
steps:
25-
- name: Release GitHub Actions
26-
uses: technote-space/release-github-actions@v1
27-
with:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
30-
```
31-
32-
## ACCESS_TOKEN
16+
1. Setup workflow
17+
e.g. `.github/workflows/release.yml`
18+
```yaml
19+
on: release
20+
name: Release
21+
jobs:
22+
release:
23+
name: Release GitHub Actions
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Release GitHub Actions
27+
uses: technote-space/release-github-actions@v1
28+
with:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
31+
```
32+
33+
### Required parameter
34+
#### ACCESS_TOKEN
3335
1. Generate a [personal access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) with the public_repo or repo scope.
3436
(repo is required for private repositories).
3537
1. [Save as secrets](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables)
3638
37-
## Details
38-
### Target event
39-
- release
40-
### Target action
41-
- published
42-
### Branch name
43-
- [BRANCH_NAME](#branch_name)
44-
4539
## Options
4640
### BUILD_COMMAND
4741
Build command.
@@ -79,7 +73,7 @@ default: `'gh-actions'`
7973

8074
### CLEAN_TARGETS
8175
Files or directories to delete before release (Comma separated).
82-
default: `.github,__tests__,src,.gitignore,*.js,*.json,*.lock`
76+
default: `.github,__tests__,src,.gitignore,*.js,*.json,*.lock,_config.yml`
8377
Absolute path and `..` are not permitted to use.
8478

8579
### CREATE_MAJOR_VERSION_TAG
@@ -94,6 +88,50 @@ default: `true`
9488
Set to `false` if you do not want to create a minor version tag.
9589
[Detail of tags](#tags)
9690

91+
### OUTPUT_BUILD_INFO_FILENAME
92+
Filename of build information.
93+
default: `''`
94+
Absolute path and `..` are not permitted to use.
95+
If this setting is not empty, following information is output with the file name.
96+
```json
97+
{
98+
"tagName": "${tagName}",
99+
"branch": "${branch}",
100+
"tags": [
101+
"${created_tag_1}",
102+
"${created_tag_n}"
103+
],
104+
"updated_at": "${updated_at}"
105+
}
106+
```
107+
108+
## Action event details
109+
### Target event
110+
- release
111+
### Target action
112+
- published
113+
114+
## Motivation
115+
Release package needs all dependencies like `node_modules`, but usually they are not committed.
116+
So if you want to release `GitHub Actions`, you have to do following steps.
117+
1. Develop locally on the branch for develop
118+
1. Build for release
119+
1. Commit all source code including dependencies like `node_modules`
120+
1. Add tags (consider major and minor versions)
121+
1. Push to GitHub
122+
1. Publish release
123+
124+
It is very troublesome to do this steps for every release.
125+
126+
If you use this `GitHub Action`, the steps to do are simple.
127+
1. Develop locally on the branch for develop
128+
1. Publish release
129+
1. Wait for the automated steps to finish
130+
1. Build for release
131+
1. Commit all source code including dependencies like `node_modules`
132+
1. Add tags (consider major and minor versions)
133+
1. Push to GitHub
134+
97135
## Addition
98136
### tags
99137
Tag name format must be [Semantic Versioning](https://semver.org/).

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ inputs:
2525
default: 'gh-actions'
2626
CLEAN_TARGETS:
2727
description: Files or directories to delete before release. (Comma separated)
28-
default: '.github,__tests__,src,.gitignore,*.js,*.json,*.lock'
28+
default: '.github,__tests__,src,.gitignore,*.js,*.json,*.lock,_config.yml'
2929
CREATE_MAJOR_VERSION_TAG:
3030
description: Whether to create major version tag.
3131
default: true
3232
CREATE_MINOR_VERSION_TAG:
3333
description: Whether to create minor version tag.
3434
default: true
35+
OUTPUT_BUILD_INFO_FILENAME:
36+
description: Filename of build information.
37+
default: ''
3538
branding:
3639
icon: 'tag'
3740
color: 'green'

lib/constant.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ exports.DEFAULT_COMMIT_MESSAGE = 'feat: Build for release';
44
exports.DEFAULT_COMMIT_NAME = 'GitHub Actions';
55
exports.DEFAULT_COMMIT_EMAIL = '[email protected]';
66
exports.DEFAULT_BRANCH_NAME = 'gh-actions';
7-
exports.DEFAULT_CLEAN_TARGETS = '.github,__tests__,src,.gitignore,*.js,*.json,*.lock';
7+
exports.DEFAULT_CLEAN_TARGETS = '.github,__tests__,src,.gitignore,*.js,*.json,*.lock,_config.yml';
8+
exports.DEFAULT_OUTPUT_BUILD_INFO_FILENAME = '';
89
exports.TARGET_EVENT_NAME = 'release';
910
exports.TARGET_EVENT_ACTION = 'published';
1011
exports.SEARCH_BUILD_COMMAND_TARGETS = [

lib/main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1111
return (mod && mod.__esModule) ? mod : { "default": mod };
1212
};
1313
Object.defineProperty(exports, "__esModule", { value: true });
14+
const path_1 = __importDefault(require("path"));
1415
const core_1 = require("@actions/core");
1516
const github_1 = require("@actions/github");
1617
const signale_1 = __importDefault(require("signale"));
@@ -19,13 +20,17 @@ const misc_1 = require("./utils/misc");
1920
function run() {
2021
return __awaiter(this, void 0, void 0, function* () {
2122
try {
22-
signale_1.default.info(`Event: ${github_1.context.eventName}`);
23-
signale_1.default.info(`Action: ${github_1.context.action}`);
23+
const version = misc_1.getBuildVersion(path_1.default.resolve(__dirname, '..', 'build.json'));
24+
if ('string' === typeof version) {
25+
signale_1.default.info('Version: %s', version);
26+
}
27+
signale_1.default.info('Event: %s', github_1.context.eventName);
28+
signale_1.default.info('Action: %s', github_1.context.action);
2429
if (!misc_1.isTargetEvent(github_1.context)) {
2530
signale_1.default.info('This is not target event.');
2631
return;
2732
}
28-
signale_1.default.info(`Tag name: ${github_1.context.payload.release.tag_name}`);
33+
signale_1.default.info('Tag name: %s', github_1.context.payload.release.tag_name);
2934
if (!misc_1.isValidTagName(github_1.context.payload.release.tag_name)) {
3035
signale_1.default.info('This tag name is invalid.');
3136
return;

lib/utils/command.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1414
const fs_1 = __importDefault(require("fs"));
1515
const path_1 = __importDefault(require("path"));
1616
const signale_1 = __importDefault(require("signale"));
17+
const moment_1 = __importDefault(require("moment"));
1718
const child_process_1 = require("child_process");
1819
const misc_1 = require("./misc");
1920
exports.deploy = (tagName, octokit, context) => __awaiter(this, void 0, void 0, function* () {
@@ -25,7 +26,9 @@ exports.deploy = (tagName, octokit, context) => __awaiter(this, void 0, void 0,
2526
fs_1.default.mkdirSync(pushDir, { recursive: true });
2627
if (!(yield cloneForBranch(pushDir, branchName, context)))
2728
return;
28-
if (!(yield exports.prepareFiles(buildDir, pushDir, context)))
29+
if (!(yield exports.prepareFiles(buildDir, pushDir, tagName, context)))
30+
return;
31+
if (!(yield createBuildInfoFile(buildDir, tagName, branchName)))
2932
return;
3033
if (!(yield copyFiles(buildDir, pushDir)))
3134
return;
@@ -37,13 +40,31 @@ exports.deploy = (tagName, octokit, context) => __awaiter(this, void 0, void 0,
3740
return;
3841
yield updateRelease(tagName, octokit, context);
3942
});
40-
exports.prepareFiles = (buildDir, pushDir, context) => __awaiter(this, void 0, void 0, function* () {
43+
exports.prepareFiles = (buildDir, pushDir, tagName, context) => __awaiter(this, void 0, void 0, function* () {
4144
signale_1.default.info('Preparing files for release');
4245
fs_1.default.mkdirSync(buildDir, { recursive: true });
4346
yield cloneForBuild(buildDir, context);
4447
yield runBuild(buildDir);
4548
return true;
4649
});
50+
const createBuildInfoFile = (buildDir, tagName, branchName) => __awaiter(this, void 0, void 0, function* () {
51+
const filename = misc_1.getOutputBuildInfoFilename();
52+
if (!filename)
53+
return true;
54+
signale_1.default.info('Creating build info file');
55+
const filepath = path_1.default.resolve(buildDir, filename);
56+
const dir = path_1.default.dirname(filepath);
57+
if (!fs_1.default.existsSync(dir)) {
58+
fs_1.default.mkdirSync(dir, { recursive: true });
59+
}
60+
fs_1.default.writeFileSync(filepath, JSON.stringify({
61+
'version': tagName,
62+
'branch': branchName,
63+
'tags': misc_1.getCreateTags(tagName),
64+
'updated_at': moment_1.default().toISOString(),
65+
}));
66+
return true;
67+
});
4768
const cloneForBranch = (pushDir, branchName, context) => __awaiter(this, void 0, void 0, function* () {
4869
signale_1.default.info('Cloning the branch %s from the remote repo', branchName);
4970
const url = misc_1.getGitUrl(context);
@@ -97,7 +118,7 @@ const push = (pushDir, tagName, branchName, context) => __awaiter(this, void 0,
97118
const url = misc_1.getGitUrl(context);
98119
const tagNames = misc_1.getCreateTags(tagName);
99120
for (const tagName of tagNames) {
100-
yield execAsync(`git -C ${pushDir} push --delete "${url}" tag ${tagName}`, true, 'git push --delete origin tag', true);
121+
yield execAsync(`git -C ${pushDir} push --delete "${url}" tag ${tagName}`, true, `git push --delete origin tag ${tagName}`, true);
101122
}
102123
yield execAsync(`git -C ${pushDir} tag -l | xargs git -C ${pushDir} tag -d`);
103124
yield execAsync(`git -C ${pushDir} fetch "${url}" --tags`, true, 'git fetch origin --tags');

lib/utils/misc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ exports.getCommitEmail = () => core_1.getInput('COMMIT_EMAIL') || constant_1.DEF
4242
exports.getBranchName = () => core_1.getInput('BRANCH_NAME') || constant_1.DEFAULT_BRANCH_NAME;
4343
exports.isCreateMajorVersionTag = () => getBoolValue(core_1.getInput('CREATE_MAJOR_VERSION_TAG') || 'true');
4444
exports.isCreateMinorVersionTag = () => getBoolValue(core_1.getInput('CREATE_MINOR_VERSION_TAG') || 'true');
45+
exports.getOutputBuildInfoFilename = () => {
46+
const filename = (core_1.getInput('OUTPUT_BUILD_INFO_FILENAME') || constant_1.DEFAULT_OUTPUT_BUILD_INFO_FILENAME).trim();
47+
if (filename.startsWith('/') || filename.includes('..'))
48+
return '';
49+
return filename;
50+
};
51+
exports.getBuildVersion = (filepath) => {
52+
if (!fs_1.default.existsSync(filepath)) {
53+
return false;
54+
}
55+
const json = JSON.parse(fs_1.default.readFileSync(filepath, 'utf8'));
56+
if (json && 'tagName' in json) {
57+
return json['tagName'];
58+
}
59+
return false;
60+
};
4561
exports.getCreateTags = (tagName) => {
4662
const tagNames = [tagName];
4763
if (exports.isCreateMajorVersionTag()) {

node_modules/.yarn-integrity

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)