Merge pull request #1 from rapidaai/redesign-theme #71
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: Build, Deploy to Azure CDN, and Publish to npm | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| build_and_deploy: | |
| name: Build and Deploy | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| env: | |
| AZURE_STORAGE_CONTAINER: "$web" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.14.0" | |
| - name: Use npm with trusted publishing support | |
| run: npm install -g npm@11.5.1 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build the project | |
| run: npm run build | |
| - name: Login to Azure | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| az login --service-principal \ | |
| -u "${{ secrets.AZURE_CLIENT_ID }}" \ | |
| -p "${{ secrets.AZURE_CLIENT_SECRET }}" \ | |
| --tenant "${{ secrets.AZURE_TENANT_ID }}" \ | |
| -o none | |
| - name: Upload to Azure Storage | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }} | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| # Latest - short cache | |
| az storage blob upload \ | |
| --account-name "$AZURE_STORAGE_ACCOUNT" \ | |
| --container-name "$AZURE_STORAGE_CONTAINER" \ | |
| --name "public/scripts/app.min.js" \ | |
| --file "./dist/app.min.js" \ | |
| --content-type "application/javascript" \ | |
| --content-cache-control "public,max-age=3600" \ | |
| --overwrite true \ | |
| --auth-mode login | |
| # Versioned - immutable cache for pinning | |
| az storage blob upload \ | |
| --account-name "$AZURE_STORAGE_ACCOUNT" \ | |
| --container-name "$AZURE_STORAGE_CONTAINER" \ | |
| --name "public/scripts/v${VERSION}/app.min.js" \ | |
| --file "./dist/app.min.js" \ | |
| --content-type "application/javascript" \ | |
| --content-cache-control "public,max-age=31536000,immutable" \ | |
| --overwrite true \ | |
| --auth-mode login | |
| - name: Purge Azure CDN cache | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| AZURE_CDN_RESOURCE_GROUP: ${{ secrets.AZURE_CDN_RESOURCE_GROUP }} | |
| AZURE_CDN_PROFILE_NAME: ${{ secrets.AZURE_CDN_PROFILE_NAME }} | |
| AZURE_CDN_ENDPOINT_NAME: ${{ secrets.AZURE_CDN_ENDPOINT_NAME }} | |
| run: | | |
| az cdn endpoint purge \ | |
| --resource-group "$AZURE_CDN_RESOURCE_GROUP" \ | |
| --profile-name "$AZURE_CDN_PROFILE_NAME" \ | |
| --name "$AZURE_CDN_ENDPOINT_NAME" \ | |
| --content-paths "/public/scripts/app.min.js" | |
| - name: Publish to npm | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| PKG=$(node -p "require('./package.json').name") | |
| VER=$(node -p "require('./package.json').version") | |
| if npm view "${PKG}@${VER}" version 2>/dev/null; then | |
| echo "npm: ${PKG}@${VER} already published — skipping" | |
| else | |
| npm publish --access public --provenance | |
| echo "npm: published ${PKG}@${VER}" | |
| fi | |
| create_release: | |
| name: Create Release | |
| needs: build_and_deploy | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get version and create tag | |
| id: version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "TAG_NAME=v${VERSION}" >> $GITHUB_OUTPUT | |
| if git tag -l "v${VERSION}" | grep -q "v${VERSION}"; then | |
| echo "TAG_EXISTS=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "TAG_EXISTS=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create and push tag | |
| if: steps.version.outputs.TAG_EXISTS == 'false' | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "${{ steps.version.outputs.TAG_NAME }}" -m "Release ${{ steps.version.outputs.TAG_NAME }}" | |
| git push origin "${{ steps.version.outputs.TAG_NAME }}" | |
| - name: Create GitHub Release | |
| if: steps.version.outputs.TAG_EXISTS == 'false' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| { | |
| echo "# Release ${{ steps.version.outputs.TAG_NAME }}" | |
| echo "" | |
| echo "## Deployment" | |
| echo "| Target | URL |" | |
| echo "|--------|-----|" | |
| echo "| CDN (latest) | \`https://cdn-01.rapida.ai/public/scripts/app.min.js\` |" | |
| echo "| CDN (pinned) | \`https://cdn-01.rapida.ai/public/scripts/v${{ steps.version.outputs.VERSION }}/app.min.js\` |" | |
| echo "| npm | \`npm i @rapidaai/web-widget@${{ steps.version.outputs.VERSION }}\` |" | |
| echo "" | |
| echo "## Changes" | |
| echo "- Commit: $(git rev-parse --short HEAD)" | |
| } > release-notes.md | |
| gh release create "${{ steps.version.outputs.TAG_NAME }}" \ | |
| --title "Release ${{ steps.version.outputs.TAG_NAME }}" \ | |
| --notes-file release-notes.md |