-
Notifications
You must be signed in to change notification settings - Fork 1
70 lines (63 loc) · 1.85 KB
/
create_github_release.yml
File metadata and controls
70 lines (63 loc) · 1.85 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
name: Create GitHub Release
on:
pull_request:
types: [closed]
branches:
- master
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check if PR was merged
run: |
if [ "${{ github.event.pull_request.merged }}" != "true" ]; then
echo "PR was not merged, skipping."
exit 78
fi
- name: Checkout code
uses: actions/checkout@v3.1.0
with:
fetch-depth: 0
- name: Define TAG
run: |
export VERSION=$(cat react-frontend/package.json | jq '.version' | tr -d '"')
echo "TAG=v$VERSION" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
uses: actions/github-script@v6
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@v6
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
})