-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (96 loc) · 3.12 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
99
100
101
102
103
104
105
106
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 versioon from package.json
runs-on: ubuntu-latest
needs:
- check-release
if: ${{ startsWith(github.head_ref, 'release/') && (needs.check-release.outputs.is_release > 0)}}
outputs:
app-version: ${{ steps.identify-version.outputs.app-version }}
app-version-text: ${{ steps.identify-version.outputs.app-version-text }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Parse package.json
id: identify-version
run: |
APP_VERSION="$(cat ./package.json |jq .version|sed -e 's/"//g'| head -n1)"
if [ ! -n "${APP_VERSION}" ]; then
exit 255
fi
echo "Detected the version: ${APP_VERSION}"
echo "app-version=${APP_VERSION}" >>"${GITHUB_OUTPUT}"
echo "app-version-text=v${APP_VERSION}" >>"${GITHUB_OUTPUT}"
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: Configration for git
run: |
git config --global user.name "${GH_USER}"
git config --global user.email "${GH_EMAIL}"
- 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}"