-
Notifications
You must be signed in to change notification settings - Fork 37
116 lines (104 loc) · 4.09 KB
/
release.yaml
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
name: Add Artifacts for Release
on:
workflow_dispatch:
inputs:
tag:
description: "Draft a release in specific tag, e.g. v1.0.0"
required: false
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+" # Release only
jobs:
check-version:
name: Check pubspec.yaml version with tag
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.result }}
build_code: ${{ steps.pubspec_version.outputs.code }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Load pubspec version
id: pubspec
uses: CumulusDS/[email protected]
with:
file: pubspec.yaml
version: version
- name: Extract pubspec version and code
id: pubspec_version
run: |
PUBSPEC_VERSION=$(echo "${{ steps.pubspec.outputs.version }}" | cut -f1 -d"+")
PUBSPEC_BUILD_CODE=$(echo "${{ steps.pubspec.outputs.version }}" | cut -f2- -d"+")
echo "::set-output name=version::$PUBSPEC_VERSION"
echo "::set-output name=code::$PUBSPEC_BUILD_CODE"
- name: Get tag that trigger this workflow
id: tag
uses: actions/github-script@v6
with:
result-encoding: string
script: |
return context.eventName === 'workflow_dispatch'
? '${{ github.event.inputs.tag }}'
: context.payload.ref.replace(/\/?refs\/tags\//, '');
- name: Check version
run: test '${{ steps.tag.outputs.result }}' = 'v${{ steps.pubspec_version.outputs.version }}'
# If pushing released tag (vX.X.X), it should be fired.
# Should build some artifacts, see below.
get-release:
name: Get release
runs-on: ubuntu-latest
needs: check-version
outputs:
changelog: ${{ steps.get_release.outputs.changelog }}
steps:
# escape special characters
# https://github.com/actions/toolkit/issues/403
- name: Get Changelog from rc1
id: get_release
run: |
release=$(curl -s \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H 'Accept: application/vnd.github.v3+json' \
https://api.github.com/repos/evan361425/flutter-pos-system/releases \
| jq -c '.[] | select( .name | contains("${{ needs.check-version.outputs.tag }}"))')
[ -z "$release" ] && exit 1
if [ ! "$(echo "$release" | jq -r '.tag_name')" = "${{ needs.check-version.outputs.tag }}" ]; then
curl -X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d '{"tag_name":"${{ needs.check-version.outputs.tag }}"}' \
"https://api.github.com/repos/evan361425/flutter-pos-system/releases/$(echo "$release" | jq -r '.id')"
fi
body="$(echo "$release" | jq -r '.body')"
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
body="${body//$'## '/}"
body="${body//$'-'/•}"
echo "::set-output name=changelog::$body"
# Push changelog to repository
add-changelog:
name: Add changelog to Fastlane
runs-on: ubuntu-latest
needs:
- get-release
- check-version
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "master"
- name: Push to GitHub
run: |
file="android/fastlane/metadata/android/zh-TW/changelogs/${{ needs.check-version.outputs.build_code }}.txt"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
echo "${{ needs.get-release.outputs.changelog }}" > "$file"
git add --all
git commit . -m "release(${{ needs.check-version.outputs.tag }}): ${{ needs.check-version.outputs.build_code }}"
git push
- name: Push tag if fired by dispatch
if: ${{ github.event_name != 'workflow_dispatch' }}
run: |
git tag ${{ github.event.inputs.tag }}
git push origin --tags