Skip to content

Fix release CI

Fix release CI #17

Workflow file for this run

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 }}