-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
135 lines (117 loc) · 4.63 KB
/
create-a-release-draft.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Create a release draft
# Caution:
# the use of "pull_request_target" trigger allows to successfully
# run workflow even when triggered from a fork. The trigger grants
# access to repo's secrets and gives write permission to the runner.
# This can be used to run malicious code on untrusted PR, so, please
# DO NOT checkout any PR's ongoing commits (aka github.event.pull_request.head.sha)
# while using this trigger.
on:
pull_request_target:
branches:
- next
types: [closed]
jobs:
# If pull request was merged then we should check for a package version update
check-version-changing:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
# Checkout to target branch
- uses: actions/checkout@v2
with:
fetch-depth: 0
# Get package new version name
- name: Get package info
id: packageNew
uses: codex-team/action-nodejs-package-info@v1
# Checkout to the base commit before merge
- name: Checkout to the base commit before merge
run: git checkout ${{ github.event.pull_request.base.sha }}
# Get package old version name
- name: Get package info
id: packageOld
uses: codex-team/action-nodejs-package-info@v1
# Stop workflow if version was not changed
- name: Stop workflow if version was not changed
if: steps.packageOld.outputs.version == steps.packageNew.outputs.version
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel
# Create a new draft release
release-draft:
needs: check-version-changing
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Checkout to target branch
- uses: actions/checkout@v2
with:
# Pull submodules
submodules: 'recursive'
# Setup node environment
- uses: actions/setup-node@v1
with:
node-version: 16
# Prepare, build and publish project
- name: Install dependencies
run: yarn
# Build Editor.js
- name: Build output files
run: yarn build
# Get package version name
- name: Get package info
id: package
uses: codex-team/action-nodejs-package-info@v1
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package.outputs.version }}
release_name: v${{ steps.package.outputs.version }}
# Fill release description from pull request body name
body: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}"
# Save as a draft release
draft: true
# If version name contains "-rc" suffix than mark a "pre-release" checkbox
prerelease: ${{ contains(steps.package.outputs.version, '-rc') }}
# Build and upload target Editor.js UMD build to release as artifact
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/editorjs.umd.js
asset_name: editorjs.umd.js
asset_content_type: application/javascript
# Build and upload target Editor.js MJS build to release as artifact
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/editorjs.mjs
asset_name: editorjs.mjs
asset_content_type: application/javascript
# Send a notification message
- name: Send a message
uses: codex-team/action-codexbot-notify@v1
with:
webhook: ${{ secrets.CODEX_BOT_WEBHOOK_FRONTEND }}
message: '🦥 [Draft release v${{ steps.package.outputs.version }}](${{ steps.create_release.outputs.html_url }}) for package [${{ steps.package.outputs.name }}](${{ steps.package.outputs.npmjs-link }}) has been created. Add changelog and publish it!'
parse_mode: 'markdown'
disable_web_page_preview: true