|
| 1 | +name: Build and deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: # allow manual execution |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pages: write |
| 12 | + actions: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-deploy: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout Repository |
| 20 | + uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Set up Node.js |
| 23 | + uses: actions/setup-node@v3 |
| 24 | + with: |
| 25 | + node-version: "18.x" |
| 26 | + registry-url: "https://registry.npmjs.org" |
| 27 | + |
| 28 | + - name: Install Dependencies |
| 29 | + run: npm install |
| 30 | + |
| 31 | + - name: Build project |
| 32 | + run: npm run build |
| 33 | + |
| 34 | + - name: Extract UPLOAD_MODE from .env |
| 35 | + run: | |
| 36 | + UPLOAD_MODE=$(grep '^[^#]*UPLOAD_MODE' .env | cut -d '=' -f2) |
| 37 | + if [ -z "$UPLOAD_MODE" ]; then |
| 38 | + echo "Error: UPLOAD_MODE is not set in .env." |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + echo "UPLOAD_MODE=$UPLOAD_MODE" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + - name: Set up Environment Variables |
| 44 | + if: ${{ env.UPLOAD_MODE == 'MAP_STORAGE' }} |
| 45 | + run: | |
| 46 | + # MAP_STORAGE_API_KEY must always come from GitHub Secrets in CI |
| 47 | + if [ -z "${{ secrets.MAP_STORAGE_API_KEY }}" ]; then |
| 48 | + echo "Error: MAP_STORAGE_API_KEY is not set in GitHub Secrets." |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + echo "MAP_STORAGE_API_KEY=${{ secrets.MAP_STORAGE_API_KEY }}" >> $GITHUB_ENV |
| 52 | +
|
| 53 | + # MAP_STORAGE_URL can fall back to .env if not in GitHub Secrets |
| 54 | + if [ -n "${{ secrets.MAP_STORAGE_URL }}" ]; then |
| 55 | + echo "MAP_STORAGE_URL=${{ secrets.MAP_STORAGE_URL }}" >> $GITHUB_ENV |
| 56 | + else |
| 57 | + MAP_STORAGE_URL=$(grep '^[^#]*MAP_STORAGE_URL' .env | cut -d '=' -f2) |
| 58 | + if [ -z "$MAP_STORAGE_URL" ]; then |
| 59 | + echo "Error: MAP_STORAGE_URL is not set in GitHub Secrets or .env." |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + echo "MAP_STORAGE_URL=$MAP_STORAGE_URL" >> $GITHUB_ENV |
| 63 | + fi |
| 64 | +
|
| 65 | + # UPLOAD_DIRECTORY can fall back to .env if not in GitHub Secrets, and to an arbitrary value if not in .env |
| 66 | + if [ -n "${{ secrets.UPLOAD_DIRECTORY }}" ]; then |
| 67 | + echo "UPLOAD_DIRECTORY=${{ secrets.UPLOAD_DIRECTORY }}" >> $GITHUB_ENV |
| 68 | + else |
| 69 | + UPLOAD_DIRECTORY=$(grep '^[^#]*UPLOAD_DIRECTORY' .env | cut -d '=' -f2) |
| 70 | + if [ -n "$UPLOAD_DIRECTORY" ]; then |
| 71 | + echo "UPLOAD_DIRECTORY=$UPLOAD_DIRECTORY" >> $GITHUB_ENV |
| 72 | + else |
| 73 | + USERNAME=${{ github.repository_owner }} |
| 74 | + REPO=${{ github.event.repository.name }} |
| 75 | + UPLOAD_DIRECTORY="${USERNAME}-${REPO}" |
| 76 | + echo "UPLOAD_DIRECTORY=$UPLOAD_DIRECTORY" >> $GITHUB_ENV |
| 77 | + echo "Warning: UPLOAD_DIRECTORY was not found; set to $UPLOAD_DIRECTORY." |
| 78 | + fi |
| 79 | + fi |
| 80 | +
|
| 81 | + - name: Deploy using WA Map Storage |
| 82 | + if: ${{ env.UPLOAD_MODE == 'MAP_STORAGE' }} |
| 83 | + run: npm run upload-only |
| 84 | + |
| 85 | + - name: Deploy using Github Pages |
| 86 | + if: ${{ env.UPLOAD_MODE == 'GH_PAGES' }} |
| 87 | + uses: JamesIves/github-pages-deploy-action@releases/v3 |
| 88 | + with: |
| 89 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + BRANCH: gh-pages |
| 91 | + FOLDER: dist/ |
| 92 | + BASE_BRANCH: master |
| 93 | + |
0 commit comments