diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index e2faabef..953ea2a0 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -1,6 +1,10 @@ -name: Optimize map and deploy +name: Build and deploy -on: [push] +on: + push: + branches: + - master + workflow_dispatch: # allow manual execution permissions: contents: write @@ -8,50 +12,75 @@ permissions: 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: @@ -59,3 +88,4 @@ jobs: BRANCH: gh-pages FOLDER: dist/ BASE_BRANCH: master + diff --git a/package.json b/package.json index eed35d0b..bfb143a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "workadventure-map-starter-kit", - "version": "3.3.17", + "version": "3.3.18", "license": "MIT", "type": "module", "scripts": {