Skip to content

Commit

Permalink
Fix Github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ValdoTR committed Oct 3, 2024
1 parent da173bc commit c78fcf3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
82 changes: 56 additions & 26 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,91 @@
name: Optimize map and deploy
name: Build and deploy

on: [push]
on:
push:
branches:
- master
workflow_dispatch: # allow manual execution

permissions:
contents: write
pages: write
actions: write

jobs:
deploy:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout Repository
uses: actions/checkout@v3

- uses: actions/setup-node@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"

- name: "Install dependencies"
- name: Install Dependencies
run: npm install

- name: "Build scripts"
- name: Build project
run: npm run build

- name: Get API key from secrets
env:
MAP_STORAGE_API_KEY: ${{ secrets.MAP_STORAGE_API_KEY }}
run: echo "MAP_STORAGE_API_KEY=${MAP_STORAGE_API_KEY}" >> $GITHUB_ENV
- name: Set up Environment Variables
run: |
# MAP_STORAGE_API_KEY must always come from GitHub Secrets in CI
if [ -z "${{ secrets.MAP_STORAGE_API_KEY }}" ]; then
echo "Error: MAP_STORAGE_API_KEY is not set in GitHub Secrets."
exit 1
fi
echo "MAP_STORAGE_API_KEY=${{ secrets.MAP_STORAGE_API_KEY }}" >> $GITHUB_ENV
- name: Get Map storage URL from secrets
env:
MAP_STORAGE_URL: ${{ secrets.MAP_STORAGE_URL }}
run: echo "MAP_STORAGE_URL=${MAP_STORAGE_URL}" >> $GITHUB_ENV
# MAP_STORAGE_URL can fall back to .env if not in GitHub Secrets
if [ -n "${{ secrets.MAP_STORAGE_URL }}" ]; then
echo "MAP_STORAGE_URL=${{ secrets.MAP_STORAGE_URL }}" >> $GITHUB_ENV
else
MAP_STORAGE_URL=$(grep '^[^#]*MAP_STORAGE_URL' .env | cut -d '=' -f2)
if [ -z "$MAP_STORAGE_URL" ]; then
echo "Error: MAP_STORAGE_URL is not set in GitHub Secrets or .env."
exit 1
fi
echo "MAP_STORAGE_URL=$MAP_STORAGE_URL" >> $GITHUB_ENV
fi
- name: Get Map storage directory from secrets
env:
DIRECTORY: ${{ secrets.DIRECTORY }}
run: echo "DIRECTORY=${DIRECTORY}" >> $GITHUB_ENV
# UPLOAD_DIRECTORY can fall back to .env if not in GitHub Secrets, and to an arbitrary value if not in .env
if [ -n "${{ secrets.UPLOAD_DIRECTORY }}" ]; then
echo "UPLOAD_DIRECTORY=${{ secrets.UPLOAD_DIRECTORY }}" >> $GITHUB_ENV
else
UPLOAD_DIRECTORY=$(grep '^[^#]*UPLOAD_DIRECTORY' .env | cut -d '=' -f2)
if [ -n "$UPLOAD_DIRECTORY" ]; then
echo "UPLOAD_DIRECTORY=$UPLOAD_DIRECTORY" >> $GITHUB_ENV
else
USERNAME=${{ github.repository_owner }}
REPO=${{ github.event.repository.name }}
UPLOAD_DIRECTORY="${USERNAME}-${REPO}"
echo "UPLOAD_DIRECTORY=$UPLOAD_DIRECTORY" >> $GITHUB_ENV
echo "Warning: UPLOAD_DIRECTORY was not found; set to $UPLOAD_DIRECTORY."
fi
fi
- name: Generate .env.secret
run: echo "MAP_STORAGE_API_KEY=${{ secrets.MAP_STORAGE_API_KEY }}" > .env.secret
# UPLOAD_MODE only come from the .env file
UPLOAD_MODE=$(grep '^[^#]*UPLOAD_MODE' .env | cut -d '=' -f2)
if [ -z "$UPLOAD_MODE" ]; then
echo "Error: UPLOAD_MODE is not set in .env."
exit 1
fi
echo "UPLOAD_MODE=$UPLOAD_MODE" >> $GITHUB_ENV
- name: Extract UPLOAD_MODE from .env
run: echo "UPLOAD_MODE=$(grep '^[^#]*UPLOAD_MODE' .env | cut -d '=' -f2)" >> $GITHUB_ENV

- name: Deploy in MAP STORAGE
- name: Deploy using WA Map Storage
if: ${{ env.UPLOAD_MODE == 'MAP_STORAGE' }}
run: npm run upload-only

- name: Deploy on GITHUB PAGES
- name: Deploy using Github Pages
if: ${{ env.UPLOAD_MODE == 'GH_PAGES' }}
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: dist/
BASE_BRANCH: master

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workadventure-map-starter-kit",
"version": "3.3.17",
"version": "3.3.18",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down

0 comments on commit c78fcf3

Please sign in to comment.