states example #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Vanilla JS to R2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| deploy_latest: | |
| description: 'Deploy as latest version' | |
| required: false | |
| default: true | |
| type: boolean | |
| jobs: | |
| deploy-vanilla: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Allow creating releases | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Get package version | |
| id: package_version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "📦 Current version: $VERSION" | |
| - name: Check if version already deployed | |
| id: check_deployed | |
| run: | | |
| VERSION="${{ steps.package_version.outputs.version }}" | |
| # Check if this version tag exists | |
| if git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
| echo "deployed=true" >> $GITHUB_OUTPUT | |
| echo "⚠️ Version $VERSION already has a git tag (likely already deployed)" | |
| else | |
| echo "deployed=false" >> $GITHUB_OUTPUT | |
| echo "✅ Version $VERSION is new and ready to deploy" | |
| fi | |
| - name: Install dependencies | |
| if: steps.check_deployed.outputs.deployed == 'false' | |
| run: npm ci | |
| - name: Build vanilla JS bundle | |
| if: steps.check_deployed.outputs.deployed == 'false' | |
| run: npm run build | |
| - name: Install AWS CLI | |
| if: steps.check_deployed.outputs.deployed == 'false' | |
| run: | | |
| curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
| unzip awscliv2.zip | |
| sudo ./aws/install | |
| - name: Deploy to Cloudflare R2 | |
| if: steps.check_deployed.outputs.deployed == 'false' | |
| run: ./scripts/deploy-vanilla.sh | |
| env: | |
| R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
| R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
| R2_BUCKET: ${{ secrets.R2_BUCKET }} | |
| R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} | |
| R2_PUBLIC_BASEURL: ${{ secrets.R2_PUBLIC_BASEURL }} | |
| - name: Create GitHub Release for Vanilla JS | |
| if: steps.check_deployed.outputs.deployed == 'false' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.package_version.outputs.version }} | |
| name: Vanilla JS v${{ steps.package_version.outputs.version }} | |
| files: | | |
| dist/landmap-vanilla.js | |
| dist/landmap-vanilla.js.map | |
| body: | | |
| ## 📦 LandMapMagic Vanilla JS v${{ steps.package_version.outputs.version }} | |
| Deployed to CDN: ${{ secrets.R2_PUBLIC_BASEURL }} | |
| ### CDN URLs | |
| - **Latest (auto-updates)**: `${{ secrets.R2_PUBLIC_BASEURL }}/js/landmap-latest.min.js` | |
| - **This version (pinned)**: `${{ secrets.R2_PUBLIC_BASEURL }}/js/landmap-${{ steps.package_version.outputs.version }}.min.js` | |
| ### Usage | |
| ```html | |
| <!-- For production, use the pinned version --> | |
| <script src="${{ secrets.R2_PUBLIC_BASEURL }}/js/landmap-${{ steps.package_version.outputs.version }}.min.js"></script> | |
| <!-- Or use latest for development --> | |
| <script src="${{ secrets.R2_PUBLIC_BASEURL }}/js/landmap-latest.min.js"></script> | |
| <script> | |
| LandMapMagic.createMap('map', { | |
| apiKey: 'your-api-key', | |
| initialVisibleLayers: ['ssurgo'] | |
| }); | |
| </script> | |
| ``` | |
| ### Also Available | |
| - NPM: `npm install landmapmagic@${{ steps.package_version.outputs.version }}` | |
| - See [README](https://github.com/staviebrock/landmapmagic.com/blob/main/README.md) for full documentation | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Version already deployed | |
| if: steps.check_deployed.outputs.deployed == 'true' | |
| run: | | |
| echo "::notice::Version ${{ steps.package_version.outputs.version }} already deployed. Skipping." | |
| echo "" | |
| echo "This version has already been deployed to R2." | |
| echo "The vanilla JS deployment happens automatically when the npm version is bumped." |