generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 3
69 lines (62 loc) · 2.3 KB
/
autoRelease.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: autoRelease
on:
push:
jobs:
run:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
- name: Add compare versions package
run: npm install compare-versions
- name: Get latest release
uses: actions/github-script@v3.1
id: get-latest-release
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
try {
var latestRelease = await github.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
});
return latestRelease.data.tag_name;
} catch (error) {
if (error.message === 'Not Found') {
return '0.0.0';
} else {
core.setFailed(error.message)
}
}
- name: Get changelog
id: changelog-reader
uses: mindsers/changelog-reader-action@v2.0.0
with:
path: ./CHANGELOG.md
- name: Compare version
uses: actions/github-script@v3.1
id: comparison
env:
currentVersion: ${{ steps.changelog-reader.outputs.version }}
latestRelease: ${{ steps.get-latest-release.outputs.result }}
with:
result-encoding: string
script: |
const compareVersions = require(`${process.env.GITHUB_WORKSPACE}/node_modules/compare-versions`);
var currentVersion = `${process.env.currentVersion}`;
var latestRelease = `${process.env.latestRelease}`;
return compareVersions.compare(currentVersion, latestRelease, ">");
- name: Create release
if: steps.comparison.outputs.result == 'true'
id: create_release
uses: actions/create-release@v1.1.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.changelog-reader.outputs.version }}
release_name: Release v${{ steps.changelog-reader.outputs.version }}
body: ${{ steps.changelog-reader.outputs.changes }}
draft: ${{ steps.changelog-reader.outputs.status == 'unreleased' }}
prerelease: ${{ steps.changelog-reader.outputs.status == 'prereleased' }}