Skip to content

Commit

Permalink
ci: split nightly & canary
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 27, 2024
1 parent 9317e68 commit c07cfc3
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 20 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Canary

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

env:
SKIP_RELEASE: "yes"
SIGNING_KEYSTORE_FILE: ./secrets/signing_key.jks
BUILD_APK_FILE: ./app/build/outputs/apk/release/app-release.apk
BUILD_AAB_FILE: ./app/build/outputs/bundle/release/app-release.aab
OUTPUT_DIR: ./dist

jobs:
canary-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: npm

- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17
cache: gradle

- name: 🚧 Do prerequisites
run: npm ci

- name: 🔢 Get version
id: app_version
run: echo "version=$(npm run --silent version:print-canary)" >> $GITHUB_OUTPUT

- name: 🔎 Check for release
run: |
last_tag=$(npm run --silent git:latest-tag)
echo "SKIP_RELEASE=$(npm run --silent git:no-affects-app-yn -- $last_tag)" >> $GITHUB_ENV
env:
TAG_NAME: v${{ steps.app_version.outputs.version }}

- name: 🔨 Generate certificate
if: env.SKIP_RELEASE == 'no'
run: |
mkdir -p $(dirname $SIGNING_KEYSTORE_FILE)
echo $SIGNING_KEYSTORE_FILE_CONTENT | base64 -di > $SIGNING_KEYSTORE_FILE
env:
SIGNING_KEYSTORE_FILE_CONTENT: ${{ secrets.SIGNING_KEYSTORE_FILE }}

- name: 🔨 Build assets
if: env.SKIP_RELEASE == 'no'
run: |
npm run prebuild
chmod +x ./gradlew
./gradlew assemble
./gradlew bundle
npm run postbuild
env:
APP_VERSION_NAME: ${{ steps.app_version.outputs.version }}
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

- name: 📝 Rename assets
if: env.SKIP_RELEASE == 'no'
run: |
mkdir -p $OUTPUT_DIR
mv $BUILD_APK_FILE $OUTPUT_DIR/symphony-v$APP_VERSION_NAME.apk
mv $BUILD_AAB_FILE $OUTPUT_DIR/symphony-v$APP_VERSION_NAME.aab
env:
APP_ID_SUFFIX: .canary
APP_VERSION_NAME: ${{ steps.app_version.outputs.version }}

- name: 🚀 Upload assets
if: env.SKIP_RELEASE == 'no'
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.app_version.outputs.version }}
artifacts: ${{ env.OUTPUT_DIR }}/*
body: "Refer [commits of v${{ steps.app_version.outputs.version }}](https://github.com/zyrouge/symphony/commits/v${{ steps.app_version.outputs.version }}) for the changes."
generateReleaseNotes: false
draft: true
artifactErrorsFailBuild: true

- name: 🔖 Was Release skipped?
if: env.SKIP_RELEASE == 'yes'
run: echo "Skipping since tag $TAG_NAME already exists"
env:
TAG_NAME: v${{ steps.app_version.outputs.version }}
23 changes: 3 additions & 20 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: Nightly

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

env:
SKIP_RELEASE: "yes"
SIGNING_KEYSTORE_FILE: ./secrets/signing_key.jks
BUILD_APK_FILE: ./app/build/outputs/apk/release/app-release.apk
BUILD_AAB_FILE: ./app/build/outputs/bundle/release/app-release.aab
Expand All @@ -18,8 +15,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
Expand All @@ -40,22 +35,18 @@ jobs:
run: echo "version=$(npm run --silent version:print-nightly)" >> $GITHUB_OUTPUT

- name: 🔎 Check for release
run: |
last_tag=$(npm run --silent git:latest-tag)
echo "SKIP_RELEASE=$(npm run --silent git:no-affects-app-yn -- $last_tag)" >> $GITHUB_ENV
run: npm run --silent git:tag-exists -- $TAG_NAME
env:
TAG_NAME: v${{ steps.app_version.outputs.version }}

- name: 🔨 Generate certificate
if: env.SKIP_RELEASE == 'no'
run: |
mkdir -p $(dirname $SIGNING_KEYSTORE_FILE)
echo $SIGNING_KEYSTORE_FILE_CONTENT | base64 -di > $SIGNING_KEYSTORE_FILE
env:
SIGNING_KEYSTORE_FILE_CONTENT: ${{ secrets.SIGNING_KEYSTORE_FILE }}

- name: 🔨 Build assets
if: env.SKIP_RELEASE == 'no'
run: |
npm run prebuild
chmod +x ./gradlew
Expand All @@ -69,16 +60,14 @@ jobs:
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

- name: 📝 Rename assets
if: env.SKIP_RELEASE == 'no'
run: |
mkdir -p $OUTPUT_DIR
mv $BUILD_APK_FILE $OUTPUT_DIR/symphony-nightly-v$APP_VERSION_NAME.apk
mv $BUILD_AAB_FILE $OUTPUT_DIR/symphony-nightly-v$APP_VERSION_NAME.aab
mv $BUILD_APK_FILE $OUTPUT_DIR/symphony-v$APP_VERSION_NAME.apk
mv $BUILD_AAB_FILE $OUTPUT_DIR/symphony-v$APP_VERSION_NAME.aab
env:
APP_VERSION_NAME: ${{ steps.app_version.outputs.version }}

- name: 🚀 Upload assets
if: env.SKIP_RELEASE == 'no'
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.app_version.outputs.version }}
Expand All @@ -88,9 +77,3 @@ jobs:
draft: false
prerelease: true
artifactErrorsFailBuild: true

- name: 🔖 Was Release skipped?
if: env.SKIP_RELEASE == 'yes'
run: echo "Skipping since tag $TAG_NAME already exists"
env:
TAG_NAME: v${{ steps.app_version.outputs.version }}
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ android {

buildTypes {
getByName("release") {
applicationIdSuffix = System.getenv("APP_ID_SUFFIX")
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
Expand Down
14 changes: 14 additions & 0 deletions cli/version/print-canary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Git } from "../helpers/git";
import { Versioner } from "../helpers/version";

const main = async () => {
const { versionCode } = await Versioner.getVersion();
const sha = await Git.getLatestRevisionShort();
const time = await Git.getRevisionDate(sha);
const year = time.getFullYear();
const month = time.getMonth() + 1;
const versionName = `${year}.${month}.${versionCode + 1}-canary+${sha}`;
console.log(versionName);
};

main();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"version:bump": "tsx ./cli/version/bump.ts",
"version:print": "tsx ./cli/version/print.ts",
"version:print-nightly": "tsx ./cli/version/print-nightly.ts",
"version:print-canary": "tsx ./cli/version/print-canary.ts",
"git:tag-exists": "tsx ./cli/git/tag-exists.ts",
"git:tag-exists-yn": "tsx ./cli/git/tag-exists-yn.ts",
"git:no-affects-app-yn": "tsx ./cli/git/no-affects-app-yn.ts",
Expand Down

0 comments on commit c07cfc3

Please sign in to comment.