Skip to content

Commit

Permalink
ci: nightly builds
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 24, 2023
1 parent bbbfa71 commit cf3f2d5
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 44 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

env:
SIGNING_KEYSTORE_FILENAME: signing_key.jks
SIGNING_KEYSTORE_FILE: ./signing_key.jks
BUILD_APK_FILE: ./app/build/outputs/apk/release/app-release.apk

jobs:
Expand All @@ -25,7 +25,6 @@ jobs:
- name: 🔨 Generate certificate
run: echo $SIGNING_KEYSTORE_FILE_CONTENT | base64 -di > $SIGNING_KEYSTORE_FILE
env:
SIGNING_KEYSTORE_FILE: ./${{ env.SIGNING_KEYSTORE_FILENAME }}
SIGNING_KEYSTORE_FILE_CONTENT: ${{ secrets.SIGNING_KEYSTORE_FILE }}

- name: 🔨 Build apk
Expand All @@ -34,7 +33,6 @@ jobs:
chmod +x ./gradlew
./gradlew build
env:
SIGNING_KEYSTORE_FILE: ../${{ env.SIGNING_KEYSTORE_FILENAME }}
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Nightly

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

env:
SIGNING_KEYSTORE_FILE: ./signing_key.jks
BUILD_APK_FILE: ./app/build/outputs/apk/release/app-release.apk
OUTPUT_DIR: ./dist

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm

- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 21
cache: gradle

- name: 🚧 Do prerequisites
run: npm ci

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

- name: 🔎 Check for release
run: npm run --silent git:tag-exists -- $TAG_NAME
env:
TAG_NAME: v${{ steps.app_version.outputs.version }}

- name: 🔨 Generate certificate
run: echo $SIGNING_KEYSTORE_FILE_CONTENT | base64 -di > $SIGNING_KEYSTORE_FILE
env:
SIGNING_KEYSTORE_FILE_CONTENT: ${{ secrets.SIGNING_KEYSTORE_FILE }}

- name: 🔨 Build apk
run: |
npm run prebuild
chmod +x ./gradlew
./gradlew build
env:
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

- name: 📝 Rename apk
run: mv $BUILD_APK_FILE $OUTPUT_DIR/symphony-nightly-v$APP_VERSION_NAME.apk
env:
APP_VERSION_NAME: ${{ steps.app_version.outputs.version }}

- name: 🚀 Upload apk
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.app_version.outputs.version }}
artifacts: ${{ env.OUTPUT_DIR }}/*
generateReleaseNotes: true
draft: false
prerelease: true
artifactErrorsFailBuild: true
47 changes: 8 additions & 39 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ on:
workflow_dispatch:

env:
SIGNING_KEYSTORE_FILENAME: signing_key.jks
SIGNING_KEYSTORE_FILE: ./signing_key.jks
BUILD_APK_FILE: ./app/build/outputs/apk/release/app-release.apk
OUTPUT_DIR: ./dist

jobs:
build:
Expand All @@ -22,42 +23,24 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17
java-version: 21
cache: gradle

- name: 🚧 Do prerequisites
run: npm ci

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

- name: 🔎 Check for release
uses: actions/github-script@v6
run: npm run --silent git:tag-exists -- $TAG_NAME
env:
APP_VERSION_NAME: ${{ steps.app_version.outputs.version }}
with:
script: |
const tagName = `v${process.env["APP_VERSION_NAME"]}`;
let statusCode;
try {
const result = await github.rest.repos.getReleaseByTag({
tag: tagName,
owner: context.repo.owner,
repo: context.repo.repo,
});
statusCode = result.status;
} catch (err) {
statusCode = err.status;
}
if (statusCode !== 404) {
throw new Error(`${tagName} tag already exists (received status code: ${statusCode})`);
}
TAG_NAME: v${{ steps.app_version.outputs.version }}

- name: 🔨 Generate certificate
run: echo $SIGNING_KEYSTORE_FILE_CONTENT | base64 -di > $SIGNING_KEYSTORE_FILE
env:
SIGNING_KEYSTORE_FILE: ./${{ env.SIGNING_KEYSTORE_FILENAME }}
SIGNING_KEYSTORE_FILE_CONTENT: ${{ secrets.SIGNING_KEYSTORE_FILE }}

- name: 🔨 Build apk
Expand All @@ -66,34 +49,20 @@ jobs:
chmod +x ./gradlew
./gradlew build
env:
SIGNING_KEYSTORE_FILE: ../${{ env.SIGNING_KEYSTORE_FILENAME }}
SIGNING_KEYSTORE_PASSWORD: ${{ secrets.SIGNING_KEYSTORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}

- name: 📝 Rename apk
uses: actions/github-script@v6
id: app_binary
run: mv $BUILD_APK_FILE $OUTPUT_DIR/symphony-v$APP_VERSION_NAME.apk
env:
APP_VERSION_NAME: ${{ steps.app_version.outputs.version }}
with:
result-encoding: string
script: |
const fs = require("fs");
const path = require("path");
const buildApkFile = process.env["BUILD_APK_FILE"];
const appVersionName = process.env["APP_VERSION_NAME"];
const releaseApkFile = path.join(
buildApkFile, `../symphony-v${appVersionName}.apk`
);
fs.copyFileSync(buildApkFile, releaseApkFile);
return releaseApkFile;

- name: 🚀 Upload apk
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.app_version.outputs.version }}
artifacts: ${{ steps.app_binary.outputs.result }}
artifacts: ${{ env.OUTPUT_DIR }}/*
generateReleaseNotes: true
draft: true
artifactErrorsFailBuild: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ node_modules
*.g.json
phrasey-dist
app/src/main/assets/i18n
dist
9 changes: 9 additions & 0 deletions cli/git/ref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { spawnSync } from "child_process";

const main = async () => {
const proc = spawnSync("git", ["rev-parse", "--short", "HEAD"]);
if (proc.status !== 0) throw new Error(`Unable to get ref`);
console.log(proc.stdout.toString().trim());
};

main();
17 changes: 17 additions & 0 deletions cli/git/tag-exists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { spawnSync } from "child_process";

const main = async () => {
const [tag] = process.argv.slice(2);
if (!tag) throw new Error("Missing argument: tag");
const proc = spawnSync("git", [
"ls-remote",
"--exit-code",
"--tags",
"origin",
tag,
]);
if (proc.status !== 0) throw new Error(`Tag ${tag} already exists`);
console.log(`Tag ${tag} is available`);
};

main();
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"i18n:build": "phrasey build -p ./.phrasey/config.toml -f toml",
"i18n:summary:base": "phrasey summary -p ./.phrasey/config.toml -f toml -o ./phrasey-dist/summary.json -s json -d",
"i18n:summary": "npm run i18n:summary:base && tsx ./cli/i18n/summary.ts",
"version:bump": "tsx ./cli/version/bump",
"version:print": "tsx ./cli/version/print",
"version:bump": "tsx ./cli/version/bump.ts",
"version:print": "tsx ./cli/version/print.ts",
"git:ref": "tsx ./cli/git/ref.ts",
"git:tag-exists": "tsx ./cli/git/tag-exists.ts",
"prebuild": "npm run i18n:build",
"release": "gh workflow run release"
},
Expand Down

0 comments on commit cf3f2d5

Please sign in to comment.