Deploy to Cloudflare Pages #11
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 to Cloudflare Pages | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| env_name: | |
| description: 'Environment to deploy' | |
| required: true | |
| default: 'dev' | |
| type: choice | |
| options: | |
| - dev | |
| - prod | |
| calver_tag: | |
| description: 'CalVer tag to promote to prod (leave blank for dev)' | |
| required: false | |
| default: '' | |
| permissions: | |
| contents: write | |
| deployments: write | |
| jobs: | |
| release-dev: | |
| if: ${{ github.event.inputs.env_name == 'dev' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| calver_tag: ${{ steps.setver.outputs.calver_tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - run: npm ci | |
| - run: npm run build | |
| # Generate CalVer tag | |
| - name: Generate CalVer tag | |
| id: setver | |
| run: | | |
| VERSION=$(date -u +"%Y.%m%d.%H%M%S") | |
| echo "calver_tag=$VERSION" >> $GITHUB_OUTPUT | |
| - run: tar -czf dist.tar.gz dist | |
| # Publish GitHub Release with CalVer | |
| - name: Create GitHub Release and upload artifact | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.setver.outputs.calver_tag }} | |
| name: Release ${{ steps.setver.outputs.calver_tag }} | |
| files: dist.tar.gz | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Deploy to Cloudflare Pages (dev) | |
| - name: Deploy to Cloudflare Pages (dev) | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| command: pages deploy dist --project-name=scp-website --branch=dev | |
| githubToken: ${{ secrets.GITHUB_TOKEN }} | |
| promote-to-prod: | |
| if: ${{ github.event.inputs.env_name == 'prod' && github.event.inputs.calver_tag != '' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Validate CalVer input | |
| - name: Validate CalVer | |
| run: | | |
| CALVER="${{ github.event.inputs.calver_tag }}" | |
| if [[ ! "$CALVER" =~ ^[0-9]{4}\.[0-9]{4}\.[0-9]{6}$ ]]; then | |
| echo "::error::Invalid CalVer tag: $CALVER" | |
| exit 1 | |
| fi | |
| # Download dist.tar.gz from GitHub Release | |
| - name: Download package from GitHub Release | |
| run: | | |
| gh release download ${{ github.event.inputs.calver_tag }} -p dist.tar.gz | |
| tar -xzf dist.tar.gz | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Deploy to Cloudflare Pages (prod) | |
| - name: Deploy to Cloudflare Pages (prod) | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| command: pages deploy dist --project-name=scp-website --branch=main | |
| githubToken: ${{ secrets.GITHUB_TOKEN }} |