-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (158 loc) · 6.62 KB
/
create-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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Create Release
on:
workflow_dispatch:
# Triggers a nightly release
push:
# Triggers a release draft whenever we push a new version tag
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
schedule:
# Nightly release every night...
- cron: "14 2 * * *" # 02:14 UTC
env:
nightly-build-branch: 'main'
jobs:
prepare:
runs-on: ubuntu-latest
name: 'Prepare jobs'
outputs:
artifact_version_suffix: ${{ steps.determine-information.outputs.artifact_version_suffix }}
should_run: ${{ steps.determine-information.outputs.should_run }}
release_name: ${{ steps.determine-information.outputs.release-name }}
tag: ${{ steps.determine-information.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: 'Determine release information'
id: determine-information
uses: actions/github-script@v7
with:
script: |
if ( "${{ github.event_name }}" === 'push' && "${{ github.ref_type }}" === 'tag' ) {
// The run was triggered by a tag being pushed
core.setOutput('tag', "${{ github.ref_name }}")
core.setOutput('should_run', 'true')
const release_name = "ScanBridge " + "${{ github.ref_name }}".substring(1) // Remove the v
core.setOutput('release-name', release_name)
console.log("Building artifacts for release of " + release_name)
} else if ( "${{ github.ref_name }}" === "${{ env.nightly-build-branch }}" ) {
// Nightly build - Check that the 'nightly' tag is not on the latest commit already
const ref = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/nightly'
})
if ( ref.data && ref.data.object ) {
if ( ref.data.object.sha != context.sha ) {
// New commits have been pushed since last nightly release
const now = new Date()
const artifact_version_suffix = "-nightly-" + now.toISOString().slice(0,10).replace(/-/g,"")
core.setOutput('artifact_version_suffix', artifact_version_suffix)
core.setOutput('tag', 'nightly')
core.setOutput('should_run', 'true')
core.setOutput('release-name', "Nightly build " + now.toISOString().slice(0,10))
console.log("Triggering nightly build")
} else {
console.log("No changes since last nightly build")
}
} else {
core.setFailed('Failed to retrieve nightly tag information')
}
} else {
core.setFailed('Run does not match triggering parameters')
}
build:
runs-on: ubuntu-latest
needs: prepare
name: 'Build & sign apk'
if: ${{ needs.prepare.outputs.should_run == 'true' }}
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Create unsigned apk
uses: ./.github/actions/build
with:
releaseBuild: 'true'
buildApk: 'true'
buildBundle: 'false'
# artifact_version_suffix: ${{ needs.prepare.outputs.artifact_version_suffix }}
- uses: noriban/sign-android-release@v5
name: Sign app APK
# ID used to access action output
id: sign_app
with:
releaseDirectory: app/build/outputs/apk/release
signingKeyBase64: ${{ secrets.RELEASE_KEY_STORE_BASE64 }}
alias: ${{ secrets.RELEASE_ALIAS }}
keyStorePassword: ${{ secrets.RELEASE_KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.RELEASE_KEY_PASSWORD }}
- name: Rename signed APK
run: mv ${{steps.sign_app.outputs.signedReleaseFile}} app/build/outputs/apk/release/ScanBridge${{ needs.prepare.outputs.artifact_version_suffix }}.apk
- name: Upload signed APK
uses: actions/upload-artifact@v4.5.0
with:
name: signed-release-apk
path: app/build/outputs/apk/release/ScanBridge${{ needs.prepare.outputs.artifact_version_suffix }}.apk
if-no-files-found: error
publish-result:
name: Publish
needs: [ build, prepare ]
if: ${{ needs.prepare.outputs.should_run == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true
path: ${{ github.workspace }}/artifacts
- name: "Zipping folder artifacts"
run: |
for D in *; do [ -d "${D}" ] && zip -r "${D}.zip" "${D}" > /dev/null && rm -rf "${D}" && echo "Zipped ${D}"; done
ls -lh
working-directory: ${{ github.workspace }}/artifacts
- name: "Update tag and prepare body (Nightly builds)"
if: ${{ needs.prepare.outputs.tag == 'nightly' }}
uses: actions/github-script@v7
with:
script: |
github.rest.git.updateRef({ // Move the nightly tag forward
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/nightly',
sha: context.sha
});
const commits = await github.rest.repos.listCommits({ // Get the last 15 commits
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 15
});
var body="Automated nightly build\n\nLast changes:"
for (c of commits.data) {
body += "\n* " + c.sha.slice(0,10) + " " + c.commit.message.split("\n")[0]
}
core.exportVariable('body', body)
- name: "Prepare release body (Regular release)"
if: ${{ needs.prepare.outputs.tag != 'nightly' }}
run: |
{
echo 'body<<EOF'
echo "This is a new minor version of ScanBridge with bug fixes and improvements from the community."
echo "See https://github.com/Chrisimx/ScanBridge/blob/${{ needs.prepare.outputs.tag }}/CHANGELOG.md for a more detailled list of changes."
echo EOF
} >> "$GITHUB_ENV"
- uses: ncipollo/release-action@v1
with:
artifacts: "artifacts/*"
prerelease: ${{ needs.prepare.outputs.tag == 'nightly' }}
allowUpdates: true
draft: true
omitDraftDuringUpdate: true
generateReleaseNotes: false
name: ${{ needs.prepare.outputs.release_name }}
body: ${{ env.body }}
removeArtifacts: true
replacesArtifacts: true
updateOnlyUnreleased: true
artifactErrorsFailBuild: true
tag: ${{ needs.prepare.outputs.tag }}