Files
lunasea/.github/workflows/prepare.yml
2022-05-10 20:30:57 -04:00

235 lines
7.5 KiB
YAML

name: Prepare
on:
workflow_call:
inputs:
flavor:
type: string
required: true
outputs:
build-number:
description: "Build Number"
value: ${{ jobs.build-details.outputs.build-number }}
build-title:
description: "Build Title"
value: ${{ jobs.build-details.outputs.build-title }}
build-version:
description: "Build Version"
value: ${{ jobs.build-details.outputs.build-version }}
enable-android:
description: "Is Android Enabled?"
value: ${{ jobs.platform-list.outputs.android }}
enable-ios:
description: "Is iOS Enabled?"
value: ${{ jobs.platform-list.outputs.ios }}
enable-linux:
description: "Is Linux Enabled?"
value: ${{ jobs.platform-list.outputs.linux }}
enable-macos:
description: "Is macOS Enabled?"
value: ${{ jobs.platform-list.outputs.macos }}
enable-windows:
description: "Is Windows Enabled?"
value: ${{ jobs.platform-list.outputs.windows }}
enable-web:
description: "Is Web Enabled?"
value: ${{ jobs.platform-list.outputs.web }}
secrets:
FIREBASE_TOKEN:
required: true
jobs:
platform-list:
name: Platform List
runs-on: ubuntu-latest
outputs:
android: ${{ steps.android.outputs.result }}
ios: ${{ steps.ios.outputs.result }}
linux: ${{ steps.linux.outputs.result }}
macos: ${{ steps.macos.outputs.result }}
windows: ${{ steps.windows.outputs.result }}
web: ${{ steps.web.outputs.result }}
steps:
- name: Check Message for Any Keywords
id: exists
uses: actions/github-script@v6
env:
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
return process.env.MESSAGE.includes("platform:");
- name: Android
id: android
uses: actions/github-script@v6
env:
EXISTS: ${{ steps.exists.outputs.result }}
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
if (process.env.EXISTS == "false") return true;
return process.env.MESSAGE.includes("platform:android");
- name: iOS
id: ios
uses: actions/github-script@v6
env:
EXISTS: ${{ steps.exists.outputs.result }}
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
if (process.env.EXISTS == "false") return true;
return process.env.MESSAGE.includes("platform:ios");
- name: Linux
id: linux
uses: actions/github-script@v6
env:
EXISTS: ${{ steps.exists.outputs.result }}
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
if (process.env.EXISTS == "false") return true;
return process.env.MESSAGE.includes("platform:linux");
- name: macOS
id: macos
uses: actions/github-script@v6
env:
EXISTS: ${{ steps.exists.outputs.result }}
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
if (process.env.EXISTS == "false") return true;
return process.env.MESSAGE.includes("platform:macos");
- name: Web
id: web
uses: actions/github-script@v6
env:
EXISTS: ${{ steps.exists.outputs.result }}
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
if (process.env.EXISTS == "false") return true;
return process.env.MESSAGE.includes("platform:web");
- name: Windows
id: windows
uses: actions/github-script@v6
env:
EXISTS: ${{ steps.exists.outputs.result }}
MESSAGE: ${{ github.event.head_commit.message || '' }}
with:
result-encoding: string
script: |
if (process.env.EXISTS == "false") return true;
return process.env.MESSAGE.includes("platform:windows");
- name: Log Platform List
env:
android: ${{ steps.android.outputs.result }}
ios: ${{ steps.ios.outputs.result }}
linux: ${{ steps.linux.outputs.result }}
macos: ${{ steps.macos.outputs.result }}
windows: ${{ steps.windows.outputs.result }}
web: ${{ steps.web.outputs.result }}
run: |
echo "Android: $android"
echo "iOS: $ios"
echo "Linux: $linux"
echo "macOS: $macos"
echo "Web: $web"
echo "Windows: $windows"
build-details:
name: Build Details
runs-on: ubuntu-latest
outputs:
build-number: ${{ steps.build-number.outputs.result }}
build-title: ${{ steps.build-title.outputs.output }}
build-version: ${{ steps.build-version.outputs.current-version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Count Commits
id: commit_count
run: |
COUNT=`git rev-list HEAD --count`
echo "::set-output name=commit_count::$COUNT"
- name: Build Number
id: build-number
uses: actions/github-script@v6
env:
COUNT: ${{ steps.commit_count.outputs.commit_count }}
with:
result-encoding: string
script: |
const count = process.env.COUNT || "0";
const base = 1000000000;
return base + Number(count);
- name: Build Version
id: build-version
uses: martinbeentjes/npm-get-version-action@v1.1.0
- name: Build Title
id: build-title
run: |
HASH=`git rev-parse --short ${{ github.sha }}`
TITLE="v${{ steps.build-version.outputs.current-version }}-${{ inputs.flavor }}-${{ steps.build-number.outputs.result }}-$HASH"
echo "::set-output name=output::$TITLE"
- name: Log Build Details
env:
number: ${{ steps.build-number.outputs.result }}
title: ${{ steps.build-title.outputs.output }}
version: ${{ steps.build-version.outputs.current-version }}
run: |
echo "Build Number: $number"
echo "Build Title: $title"
echo "Build Version: $version"
generate-files:
name: Generate Files
runs-on: ubuntu-latest
steps:
- name: Setup Environment
uses: JagandeepBrar/LunaSea/.github/actions/prepare_for_build@master
with:
firebase-token: ${{ secrets.FIREBASE_TOKEN }}
platform: test
skip-core: true
- name: Generate Environment Configuration
run: |
echo FLAVOR=${{ inputs.flavor }} > .env
echo COMMIT=${{ github.sha }} >> .env
- name: Generate Localization
run: dart ${{github.workspace }}/scripts/generate_localization.dart
- name: Generate Build Runner Files
run: flutter packages pub run build_runner build
- name: Upload Core Files
uses: actions/upload-artifact@v3
with:
name: core-files
path: |
${{ github.workspace }}/.env
${{ github.workspace }}/assets/localization
${{ github.workspace }}/lib/**/*.g.dart