-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (88 loc) · 2.88 KB
/
cd.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
name: CD
run-name: 'CD for PR: #${{github.event.pull_request.number}} ${{ github.event.pull_request.title }}'
on:
pull_request:
types:
- closed
branches:
- main
concurrency:
group: cd-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com'
GH_USER: 'github-actions[bot]'
jobs:
check-release:
name: Check release
if: ${{ startsWith(github.head_ref, 'release/') && github.event.pull_request.merged == true }}
runs-on: ubuntu-latest
outputs:
is_release: ${{ steps.check.outputs.is_release }}
steps:
- name: check
id: check
run: |
SOURCE="${{ github.head_ref }}"
TARGET="${{ github.base_ref }}"
VAR_NAME="is_release"
if [[ ${SOURCE} == release/* ]] && [[ ${TARGET} == "main" ]]; then
RESULT="${VAR_NAME}=1"
else
RESULT="${VAR_NAME}=0"
fi
echo "${RESULT}"
echo "${RESULT}" >>"${GITHUB_OUTPUT}"
test:
needs:
- check-release
if: ${{ needs.check-release.outputs.is_release > 0 }}
uses: ./.github/workflows/test.yml
get-version:
name: get version
needs:
- check-release
if: ${{ startsWith(github.head_ref, 'release/') && (needs.check-release.outputs.is_release > 0)}}
uses: ./.github/workflows/version.yml
tag:
name: Add the tag for the released version
needs:
- test
- check-release
- get-version
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
# required
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- name: Get GitHub App User ID
id: get-user-id
env:
USER_NAME: ${{ steps.app-token.outputs.app-slug }}
run: echo "user-id=$(gh api "/users/${USER_NAME}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
- name: Configration for git
env:
USER_ID: ${{ steps.get-user-id.outputs.user-id }}
USER_NAME: ${{ steps.app-token.outputs.app-slug }}
run: |
git config --global user.name "${USER_NAME}[bot]"
git config --global user.email "${USER_ID}+${USER_NAME}[bot]@users.noreply.github.com>"
- name: Checkout
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
uses: actions/checkout@v4
with:
token: ${{ env.GH_TOKEN }}
- name: Add the release tag
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_VERSION_TEXT: ${{ needs.get-version.outputs.app-version-text }}
run: |
echo "Create tag: ${APP_VERSION_TEXT}"
git tag "${APP_VERSION_TEXT}"
git push origin "${APP_VERSION_TEXT}"