MaterialKolorBuilder/.github/workflows/release.yml
2025-03-06 11:32:42 -05:00

219 lines
No EOL
6.8 KiB
YAML

name: Release Workflow
on:
release:
types: [created]
workflow_dispatch:
inputs:
version_name:
description: "Version name (e.g., 1.0.0)"
required: true
version_code:
description: "Version code (optional)"
required: false
permissions:
contents: write
env:
USE_MATERIAL_KOLOR_SUBMODULE: false
VERSION_NAME: ${{ github.event.release.tag_name || github.event.inputs.version_name }}
VERSION_CODE: ${{ github.event.inputs.version_code }}
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }}
KEYSTORE_KEY_PASSWORD: ${{ secrets.KEYSTORE_KEY_PASSWORD }}
jobs:
build:
strategy:
matrix:
target: [android, web]
name: "Build ${{ matrix.target }}"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
distribution: adopt
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Gradle Wrapper Validation
uses: gradle/actions/wrapper-validation@v4
- name: Build for ${{ matrix.target }}
run: |
if [ -n "${{ env.VERSION_CODE }}" ]; then
./scripts/build ${{ matrix.target }} ${{ env.VERSION_NAME }} --code ${{ env.VERSION_CODE }}
else
./scripts/build ${{ matrix.target }} ${{ env.VERSION_NAME }}
fi
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist
if-no-files-found: error
build-desktop:
strategy:
matrix:
os: [ubuntu, macos]
name: "Build desktop-${{ matrix.os }}"
runs-on: ${{ matrix.os }}-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
distribution: adopt
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Gradle Wrapper Validation
uses: gradle/actions/wrapper-validation@v4
- name: Build for ${{ matrix.os }}
run: |
if [ -n "${{ env.VERSION_CODE }}" ]; then
./scripts/build desktop ${{ env.VERSION_NAME }} --code ${{ env.VERSION_CODE }}
else
./scripts/build desktop ${{ env.VERSION_NAME }}
fi
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: desktop-${{ matrix.os }}
path: dist
if-no-files-found: error
release:
needs: [build, build-desktop]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if tag exists
id: check_tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
git fetch --tags
if git rev-parse -q --verify "refs/tags/${{ env.VERSION_NAME }}" >/dev/null; then
echo "Tag exists"
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "Tag does not exist"
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
else
echo "tag_exists=true" >> $GITHUB_OUTPUT
fi
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Display downloaded files
run: ls -R ./artifacts
- name: Skip update release if tag does not exist
if: steps.check_tag.outputs.tag_exists == 'false'
run: echo "Skipping update release as tag does not exist"
- name: Update Release with assets
if: steps.check_tag.outputs.tag_exists == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs').promises;
const path = require('path');
let release;
if (context.payload.release) {
// Automatic trigger from a new release
release = context.payload.release;
} else {
// Manual trigger, find release by tag (VERSION_NAME)
const { data: releaseData } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: process.env.VERSION_NAME
});
release = releaseData;
}
let uploadCount = 0;
async function uploadFilesRecursively(dir) {
const entries = await fs.readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
await uploadFilesRecursively(fullPath);
} else {
console.log(`Uploading ${entry.name} to release...`);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
name: entry.name,
data: await fs.readFile(fullPath)
});
uploadCount++;
}
}
}
const artifactsPath = path.join(process.cwd(), 'artifacts');
await uploadFilesRecursively(artifactsPath);
console.log(`Successfully uploaded ${uploadCount} assets to the release.`);
deploy:
name: "Deploy to Production"
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download web build artifacts
uses: actions/download-artifact@v4
with:
name: web
path: ./dist
- name: Copy web build artifacts
run: |
# TODO This is broken and not publishing correctly. a manual release is required after this runs
mkdir -p app/build/dist/wasmJs/productionExecutable
echo "Source directory contents:"
ls -la ./dist/
echo "Copying files..."
cp -rv ./dist/* app/build/dist/wasmJs/productionExecutable/
echo "Destination directory contents:"
ls -la app/build/dist/wasmJs/productionExecutable/
- name: Deploy to production
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_MATERIALKOLOR }}
channelId: live
projectId: materialkolor