-
Notifications
You must be signed in to change notification settings - Fork 11
135 lines (134 loc) · 5.45 KB
/
release.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: release
on:
issue_comment:
types: [created]
jobs:
details:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
name: details
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/release')
# develop to master
outputs:
base: ${{ steps.info.outputs.base }}
ref: ${{ steps.info.outputs.ref }}
is_admin: ${{ steps.info.outputs.is_admin }}
title: ${{ steps.info.outputs.title }}
body: ${{ steps.info.outputs.body }}
pr: ${{ steps.info.outputs.pr }}
steps:
- name: Get info
id: info
run: |
issue_url=$(jq -r ".issue.pull_request.url" "${GITHUB_EVENT_PATH}")
issue=$(curl "$issue_url")
base=$(echo $issue | jq -r ".base.ref")
ref=$(echo $issue | jq -r ".head.ref")
title=$(echo $issue | jq -r ".title")
body=$(echo $issue | jq -r ".body")
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
commenter=$(jq -r ".comment.user.login" "${GITHUB_EVENT_PATH}")
repo=$(jq -r ".repository.full_name" "${GITHUB_EVENT_PATH}")
project=$(jq -r ".repository.name" "${GITHUB_EVENT_PATH}")
user=$(curl -u $project:${{ secrets.GITHUB_TOKEN }} https://api.github.com/repos/$repo/collaborators/$commenter/permission)
if [ "$(echo $user | jq -r ".permission")" = "admin" ]; then
is_admin=true
else
is_admin=false
fi
pr_number=$(jq -r ".issue.number" "${GITHUB_EVENT_PATH}")
echo "##[set-output name=base;]$(echo ${base})"
echo "##[set-output name=ref;]$(echo ${ref})"
echo "##[set-output name=is_admin;]$(echo ${is_admin})"
echo "##[set-output name=user;]$(echo ${commenter})"
echo "##[set-output name=title;]$(echo ${title})"
echo "##[set-output name=body;]$(echo ${body})"
echo "##[set-output name=pr;]$(echo ${pr_number})"
author=$(jq -r ".issue.user.login" "${GITHUB_EVENT_PATH}")
org=$(jq -r ".repository.owner.login" "${GITHUB_EVENT_PATH}")
release:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x]
name: release
needs: details
if: needs.details.outputs.base == 'master' && needs.details.outputs.ref == 'develop' && needs.details.outputs.is_admin == 'true'
steps:
- name: NPM TOKEN
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: checkout
uses: actions/checkout@v2
with:
ref: 'develop'
- name: install
run: yarn
- name: build
run: yarn build
- name: verify version
run: |
if [ "$(jq -r '.version' 'lerna.json')" != "${{ needs.details.outputs.title }}" ] ; then
echo "::error file=lerna.json::version mismatch"
exit 1;
fi
# git config --global user.email "[email protected]"
# git config --global user.name "scalecube ci"
# yarn lerna version ${{ needs.details.outputs.title }} --no-push --force-publish --yes
# #git push -u origin master
# remote_repo="https://idanilt:${{secrets.GITHUB_TOKEN}}@github.com/scalecube/scalecube-js.git"
# git push "${remote_repo}" HEAD:develop
- name: merge
run: |
function retry {
local n=1
local max=5
local delay=5
while true; do
CMD="$@" && "$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command \"$CMD\" failed. Attempt $n/$max:"
sleep $delay;
else
echo "The command \"$CMD\" has failed after $n attempts."
exit 1
fi
}
done
}
sha=$(git rev-parse HEAD)
echo $sha
retry bash -c 'curl -u ci:${{ secrets.GITHUB_TOKEN }} https://api.github.com/repos/scalecube/scalecube-js/pulls/${{ needs.details.outputs.pr }}/merge \
--request PUT \
--data '"'"'{ "sha": "'"$sha"'", "merge_method": "merge", "commit_message": "", "commit_title": "Release v${{ needs.details.outputs.title }}" }'"'"' \
| grep -q "Pull Request successfully merged"'
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v${{needs.details.outputs.title}}
release_name: v${{needs.details.outputs.title}}
body: '${{ needs.details.outputs.body }}'
draft: false
prerelease: false
- name: Publish
run: |
git fetch
yarn lerna publish from-git --force-publish --yes
- name: Verify
run: scripts/./verify.sh ${{needs.details.outputs.title}}
# - name: patch
# run: |
# git config --global user.email "[email protected]"
# git config --global user.name "scalecube ci"
# git checkout develop
# yarn lerna version patch --no-push --force-publish --yes
# #git push -u origin master
# remote_repo="https://idanilt:${{secrets.GITHUB_TOKEN}}@github.com/scalecube/scalecube-js.git"
# git push "${remote_repo}" HEAD:develop