Skip to content

Commit c78fcf3

Browse files
committed
Fix Github workflow
1 parent da173bc commit c78fcf3

File tree

2 files changed

+57
-27
lines changed

2 files changed

+57
-27
lines changed
Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,91 @@
1-
name: Optimize map and deploy
1+
name: Build and deploy
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch: # allow manual execution
48

59
permissions:
610
contents: write
711
pages: write
812
actions: write
913

1014
jobs:
11-
deploy:
15+
build-and-deploy:
1216
runs-on: ubuntu-latest
1317

1418
steps:
15-
- name: Checkout
19+
- name: Checkout Repository
1620
uses: actions/checkout@v3
1721

18-
- uses: actions/setup-node@v3
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v3
1924
with:
2025
node-version: "18.x"
2126
registry-url: "https://registry.npmjs.org"
2227

23-
- name: "Install dependencies"
28+
- name: Install Dependencies
2429
run: npm install
2530

26-
- name: "Build scripts"
31+
- name: Build project
2732
run: npm run build
2833

29-
- name: Get API key from secrets
30-
env:
31-
MAP_STORAGE_API_KEY: ${{ secrets.MAP_STORAGE_API_KEY }}
32-
run: echo "MAP_STORAGE_API_KEY=${MAP_STORAGE_API_KEY}" >> $GITHUB_ENV
34+
- name: Set up Environment Variables
35+
run: |
36+
# MAP_STORAGE_API_KEY must always come from GitHub Secrets in CI
37+
if [ -z "${{ secrets.MAP_STORAGE_API_KEY }}" ]; then
38+
echo "Error: MAP_STORAGE_API_KEY is not set in GitHub Secrets."
39+
exit 1
40+
fi
41+
echo "MAP_STORAGE_API_KEY=${{ secrets.MAP_STORAGE_API_KEY }}" >> $GITHUB_ENV
3342
34-
- name: Get Map storage URL from secrets
35-
env:
36-
MAP_STORAGE_URL: ${{ secrets.MAP_STORAGE_URL }}
37-
run: echo "MAP_STORAGE_URL=${MAP_STORAGE_URL}" >> $GITHUB_ENV
43+
# MAP_STORAGE_URL can fall back to .env if not in GitHub Secrets
44+
if [ -n "${{ secrets.MAP_STORAGE_URL }}" ]; then
45+
echo "MAP_STORAGE_URL=${{ secrets.MAP_STORAGE_URL }}" >> $GITHUB_ENV
46+
else
47+
MAP_STORAGE_URL=$(grep '^[^#]*MAP_STORAGE_URL' .env | cut -d '=' -f2)
48+
if [ -z "$MAP_STORAGE_URL" ]; then
49+
echo "Error: MAP_STORAGE_URL is not set in GitHub Secrets or .env."
50+
exit 1
51+
fi
52+
echo "MAP_STORAGE_URL=$MAP_STORAGE_URL" >> $GITHUB_ENV
53+
fi
3854
39-
- name: Get Map storage directory from secrets
40-
env:
41-
DIRECTORY: ${{ secrets.DIRECTORY }}
42-
run: echo "DIRECTORY=${DIRECTORY}" >> $GITHUB_ENV
55+
# UPLOAD_DIRECTORY can fall back to .env if not in GitHub Secrets, and to an arbitrary value if not in .env
56+
if [ -n "${{ secrets.UPLOAD_DIRECTORY }}" ]; then
57+
echo "UPLOAD_DIRECTORY=${{ secrets.UPLOAD_DIRECTORY }}" >> $GITHUB_ENV
58+
else
59+
UPLOAD_DIRECTORY=$(grep '^[^#]*UPLOAD_DIRECTORY' .env | cut -d '=' -f2)
60+
if [ -n "$UPLOAD_DIRECTORY" ]; then
61+
echo "UPLOAD_DIRECTORY=$UPLOAD_DIRECTORY" >> $GITHUB_ENV
62+
else
63+
USERNAME=${{ github.repository_owner }}
64+
REPO=${{ github.event.repository.name }}
65+
UPLOAD_DIRECTORY="${USERNAME}-${REPO}"
66+
echo "UPLOAD_DIRECTORY=$UPLOAD_DIRECTORY" >> $GITHUB_ENV
67+
echo "Warning: UPLOAD_DIRECTORY was not found; set to $UPLOAD_DIRECTORY."
68+
fi
69+
fi
4370
44-
- name: Generate .env.secret
45-
run: echo "MAP_STORAGE_API_KEY=${{ secrets.MAP_STORAGE_API_KEY }}" > .env.secret
71+
# UPLOAD_MODE only come from the .env file
72+
UPLOAD_MODE=$(grep '^[^#]*UPLOAD_MODE' .env | cut -d '=' -f2)
73+
if [ -z "$UPLOAD_MODE" ]; then
74+
echo "Error: UPLOAD_MODE is not set in .env."
75+
exit 1
76+
fi
77+
echo "UPLOAD_MODE=$UPLOAD_MODE" >> $GITHUB_ENV
4678
47-
- name: Extract UPLOAD_MODE from .env
48-
run: echo "UPLOAD_MODE=$(grep '^[^#]*UPLOAD_MODE' .env | cut -d '=' -f2)" >> $GITHUB_ENV
49-
50-
- name: Deploy in MAP STORAGE
79+
- name: Deploy using WA Map Storage
5180
if: ${{ env.UPLOAD_MODE == 'MAP_STORAGE' }}
5281
run: npm run upload-only
5382

54-
- name: Deploy on GITHUB PAGES
83+
- name: Deploy using Github Pages
5584
if: ${{ env.UPLOAD_MODE == 'GH_PAGES' }}
5685
uses: JamesIves/github-pages-deploy-action@releases/v3
5786
with:
5887
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5988
BRANCH: gh-pages
6089
FOLDER: dist/
6190
BASE_BRANCH: master
91+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workadventure-map-starter-kit",
3-
"version": "3.3.17",
3+
"version": "3.3.18",
44
"license": "MIT",
55
"type": "module",
66
"scripts": {

0 commit comments

Comments
 (0)