-
Notifications
You must be signed in to change notification settings - Fork 5
73 lines (66 loc) · 1.97 KB
/
create_github_release.yml
File metadata and controls
73 lines (66 loc) · 1.97 KB
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
70
71
72
73
name: Create GitHub Release
on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
- main
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Exit if PR was closed without merging
run: |
if [ ${{ github.event_name }} == 'pull_request' ]; then
if [ ${{ github.event.pull_request.merged }} == 'false' ]; then
echo "This PR was closed without merging. Exiting..."
exit 0
fi
fi
- name: Checkout code
uses: actions/checkout@v4.2.0
with:
fetch-depth: 0
- name: Define TAG
run: |
export VERSION=$(cat package.json | jq '.version' | tr -d '"')
echo "TAG=v$VERSION" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
uses: actions/github-script@v7.0.1
with:
result-encoding: string
script: |
const tag = process.env.TAG;
const { owner, repo } = context.repo;
try {
await github.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`,
});
// If the API call doesn't throw an error, the tag exists
return true;
} catch (error) {
// If the API call throws an error, the tag doesn't exist
return false;
}
env:
TAG: ${{ env.TAG }}
- name: Create Release and Tag
uses: actions/github-script@v7.0.1
with:
result-encoding: string
retries: 3
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: process.env.TAG,
target_commitish: context.sha,
name: process.env.TAG,
generate_release_notes: true
})