Build job #159
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build job | |
on: | |
# Every Saturday at 16:00 UTC-5 | |
schedule: | |
- cron: '0 21 * * 0,3' | |
# Manual triggers | |
workflow_dispatch: | |
inputs: | |
git-ref: | |
description: Git Ref (Optional) | |
required: false | |
dry-run: | |
description: Creates a draft release | |
required: false | |
jobs: | |
build-app: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone Repository (Latest) | |
uses: actions/checkout@v3 | |
with: | |
repository: "lnreader/lnreader" | |
fetch-depth: 0 | |
if: github.event.inputs.git-ref == '' | |
- name: Clone Repository (Custom Ref) | |
uses: actions/checkout@v2 | |
if: github.event.inputs.git-ref != '' | |
with: | |
repository: "lnreader/lnreader" | |
fetch-depth: 0 | |
ref: ${{ github.event.inputs.git-ref }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Get previous release | |
id: last_release | |
uses: InsonusK/[email protected] | |
with: | |
myToken: ${{ github.token }} | |
exclude_types: "draft|prerelease" | |
view_top: 1 | |
- name: Install Dependencies | |
run: | | |
npm install --legacy-peer-deps | |
- name: Cache Gradle Wrapper | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} | |
- name: Cache Gradle Dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle-caches- | |
- name: Make Gradlew Executable | |
run: cd android && chmod +x ./gradlew | |
- name: Prepare build | |
run: | | |
set -e | |
commit_count=$(git rev-list --count HEAD) | |
echo "COMMIT_COUNT=$commit_count" >> $GITHUB_ENV | |
current_sha=$(git rev-parse --short HEAD) | |
echo "CURRENT_SHA=$current_sha" >> $GITHUB_ENV | |
prev_commit_count=$(echo "${{ steps.last_release.outputs.tag_name }}" | sed -e "s/^r//") | |
commit_count_diff=$(expr $commit_count - $prev_commit_count) | |
prev_release_sha=$(git rev-parse --short HEAD~$commit_count_diff) | |
echo "PREV_RELEASE_SHA=$prev_release_sha" >> $GITHUB_ENV | |
echo "COMMIT_LOGS<<{delimiter} | |
$(curl -H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/LNReader/lnreader/compare/$prev_release_sha...$current_sha" \ | |
| jq '[.commits[]|{message:(.commit.message | split("\n")), username:.author.login}]' \ | |
| jq -r '.[]|"- \(.message | first) (@\(.username))"') | |
{delimiter}" >> $GITHUB_ENV | |
- name: Build Android Release | |
run: | | |
cd android && ./gradlew assembleRelease --no-daemon | |
- name: Clean up build artifacts | |
run: | | |
set -e | |
cp android/app/build/outputs/apk/release/app-release.apk LNReader-r${{ env.COMMIT_COUNT }}.apk | |
sha=`sha256sum LNReader-r${{ env.COMMIT_COUNT }}.apk | awk '{ print $1 }'` | |
echo "APK_UNIVERSAL_SHA=$sha" >> $GITHUB_ENV | |
- name: Create release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: r${{ env.COMMIT_COUNT }} | |
name: LNReader Preview r${{ env.COMMIT_COUNT }} | |
body: | | |
### Commits | |
https://github.com/lnreader/lnreader/compare/${{ env.PREV_RELEASE_SHA }}...${{ env.CURRENT_SHA }} | |
${{ env.COMMIT_LOGS }} | |
--- | |
### Checksums | |
| Variant | SHA-256 | | |
| ------- | ------- | | |
| Universal | ${{ env.APK_UNIVERSAL_SHA }} | | |
files: | | |
LNReader-r${{ env.COMMIT_COUNT }}.apk | |
draft: ${{ github.event.inputs.dry-run != '' }} | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |