#18/update-logs #6
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 API | |
on: | |
pull_request: | |
paths: | |
- 'api/**' | |
push: | |
branches: | |
- main | |
paths: | |
- 'api/**' | |
workflow_dispatch: | |
inputs: | |
ACCESS_POINT_SSID: | |
description: 'Aceess Point SSID' | |
default: 'smart_power_backup' | |
ACCESS_POINT_PASSWORD: | |
description: 'Aceess Point Password' | |
default: '99999999' | |
ACCESS_POINT_GATEWAY: | |
description: 'Aceess Point Gateway' | |
default: '192.168.0.1' | |
JWT_SECRET: | |
description: 'JWT Secret' | |
required: true | |
default: 'smart-power-backup' | |
DEFAULT_USER_USERNAME: | |
description: 'Default User Username' | |
default: 'admin' | |
DEFAULT_USER_PASSWORD: | |
description: 'Default User Password' | |
default: 'admin' | |
env: | |
working-directory: api | |
jobs: | |
# Build job | |
build: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{env.working-directory}} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
.github | |
${{env.working-directory}} | |
- name: Write ENV file | |
run: | | |
touch .env | |
echo ACCESS_POINT_SSID=${{ inputs.ACCESS_POINT_SSID || secrets.ACCESS_POINT_SSID }} >> .env | |
echo ACCESS_POINT_PASSWORD=${{ inputs.ACCESS_POINT_PASSWORD || secrets.ACCESS_POINT_PASSWORD }} >> .env | |
echo ACCESS_POINT_GATEWAY=${{ inputs.ACCESS_POINT_GATEWAY || secrets.ACCESS_POINT_GATEWAY }} >> .env | |
echo JWT_SECRET=${{ inputs.JWT_SECRET || secrets.JWT_SECRET }} >> .env | |
echo DEFAULT_USER_USERNAME=${{ inputs.DEFAULT_USER_USERNAME || secrets.DEFAULT_USER_USERNAME }} >> .env | |
echo DEFAULT_USER_PASSWORD=${{ inputs.DEFAULT_USER_PASSWORD || secrets.DEFAULT_USER_PASSWORD }} >> .env | |
- name: Detect package manager | |
id: detect-package-manager | |
run: | | |
if [ -f "${{ github.workspace }}/${{env.working-directory}}/yarn.lock" ]; then | |
echo "manager=yarn" >> $GITHUB_OUTPUT | |
echo "command=install" >> $GITHUB_OUTPUT | |
echo "runner=yarn" >> $GITHUB_OUTPUT | |
exit 0 | |
elif [ -f "${{ github.workspace }}/${{env.working-directory}}/package.json" ]; then | |
echo "manager=npm" >> $GITHUB_OUTPUT | |
echo "command=ci" >> $GITHUB_OUTPUT | |
echo "runner=npx --no-install" >> $GITHUB_OUTPUT | |
exit 0 | |
else | |
echo "Unable to determine package manager" | |
exit 1 | |
fi | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: ${{ steps.detect-package-manager.outputs.manager }} | |
cache-dependency-path: ${{env.working-directory}} | |
- name: Install dependencies | |
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | |
- name: Build | |
run: ${{ steps.detect-package-manager.outputs.runner }} build | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: pico-w-software | |
path: ${{env.working-directory}}/build |