|
1 |
| -name: Optimize map and deploy |
| 1 | +name: Build and deploy |
2 | 2 |
|
3 |
| -on: [push] |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: # allow manual execution |
4 | 8 |
|
5 | 9 | permissions:
|
6 | 10 | contents: write
|
7 | 11 | pages: write
|
8 | 12 | actions: write
|
9 | 13 |
|
10 | 14 | jobs:
|
11 |
| - deploy: |
| 15 | + build-and-deploy: |
12 | 16 | runs-on: ubuntu-latest
|
13 | 17 |
|
14 | 18 | steps:
|
15 |
| - - name: Checkout |
| 19 | + - name: Checkout Repository |
16 | 20 | uses: actions/checkout@v3
|
17 | 21 |
|
18 |
| - - uses: actions/setup-node@v3 |
| 22 | + - name: Set up Node.js |
| 23 | + uses: actions/setup-node@v3 |
19 | 24 | with:
|
20 | 25 | node-version: "18.x"
|
21 | 26 | registry-url: "https://registry.npmjs.org"
|
22 | 27 |
|
23 |
| - - name: "Install dependencies" |
| 28 | + - name: Install Dependencies |
24 | 29 | run: npm install
|
25 | 30 |
|
26 |
| - - name: "Build scripts" |
| 31 | + - name: Build project |
27 | 32 | run: npm run build
|
28 | 33 |
|
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 |
33 | 42 |
|
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 |
38 | 54 |
|
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 |
43 | 70 |
|
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 |
46 | 78 |
|
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 |
51 | 80 | if: ${{ env.UPLOAD_MODE == 'MAP_STORAGE' }}
|
52 | 81 | run: npm run upload-only
|
53 | 82 |
|
54 |
| - - name: Deploy on GITHUB PAGES |
| 83 | + - name: Deploy using Github Pages |
55 | 84 | if: ${{ env.UPLOAD_MODE == 'GH_PAGES' }}
|
56 | 85 | uses: JamesIves/github-pages-deploy-action@releases/v3
|
57 | 86 | with:
|
58 | 87 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
59 | 88 | BRANCH: gh-pages
|
60 | 89 | FOLDER: dist/
|
61 | 90 | BASE_BRANCH: master
|
| 91 | + |
0 commit comments