frontend-update #215
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 Frontend Channel | |
| on: | |
| repository_dispatch: | |
| types: [frontend-update] | |
| workflow_dispatch: | |
| inputs: | |
| channel: | |
| description: "Release channel" | |
| required: true | |
| type: choice | |
| options: | |
| - stable | |
| - beta | |
| - nightly | |
| frontend_version: | |
| description: "Frontend version (e.g., 2.13.2)" | |
| required: true | |
| type: string | |
| # Allow only one concurrent deployment per channel | |
| concurrency: | |
| group: deploy-${{ github.event.client_payload.channel || inputs.channel }} | |
| cancel-in-progress: true | |
| jobs: | |
| deploy-channel: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Get parameters | |
| id: params | |
| run: | | |
| # Handle both repository_dispatch and workflow_dispatch | |
| if [ "${{ github.event_name }}" = "repository_dispatch" ]; then | |
| CHANNEL="${{ github.event.client_payload.channel }}" | |
| FRONTEND_VERSION="${{ github.event.client_payload.frontend_version }}" | |
| else | |
| CHANNEL="${{ inputs.channel }}" | |
| FRONTEND_VERSION="${{ inputs.frontend_version }}" | |
| fi | |
| echo "channel=${CHANNEL}" >> $GITHUB_OUTPUT | |
| echo "frontend_version=${FRONTEND_VERSION}" >> $GITHUB_OUTPUT | |
| echo "Channel: ${CHANNEL}" | |
| echo "Frontend version: ${FRONTEND_VERSION}" | |
| - name: Update channels.json | |
| run: | | |
| CHANNEL="${{ steps.params.outputs.channel }}" | |
| FRONTEND_VERSION="${{ steps.params.outputs.frontend_version }}" | |
| # Update channels.json with the new version | |
| jq --arg channel "$CHANNEL" --arg version "$FRONTEND_VERSION" \ | |
| '.[$channel] = $version' channels.json > channels.json.tmp | |
| mv channels.json.tmp channels.json | |
| echo "Updated channels.json:" | |
| cat channels.json | |
| - name: Commit channels.json | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add channels.json | |
| git commit -m "Update ${{ steps.params.outputs.channel }} channel to ${{ steps.params.outputs.frontend_version }}" || echo "No changes to commit" | |
| git push | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build portal | |
| run: npm run build | |
| - name: Download and extract frontend from GitHub release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| CHANNEL="${{ steps.params.outputs.channel }}" | |
| FRONTEND_VERSION="${{ steps.params.outputs.frontend_version }}" | |
| echo "Downloading frontend v${FRONTEND_VERSION} from GitHub releases..." | |
| # Create temp directory for download | |
| mkdir -p /tmp/frontend | |
| # Download the wheel from GitHub releases | |
| WHEEL_NAME="music_assistant_frontend-${FRONTEND_VERSION}-py3-none-any.whl" | |
| gh release download "${FRONTEND_VERSION}" \ | |
| --repo music-assistant/frontend \ | |
| --pattern "${WHEEL_NAME}" \ | |
| --dir /tmp/frontend | |
| WHEEL_FILE="/tmp/frontend/${WHEEL_NAME}" | |
| echo "Downloaded: ${WHEEL_FILE}" | |
| # Extract the wheel (it's a zip file) | |
| unzip -q "${WHEEL_FILE}" -d /tmp/frontend/extracted | |
| # The frontend files are in music_assistant_frontend/ | |
| FRONTEND_DIR="/tmp/frontend/extracted/music_assistant_frontend" | |
| # Copy to channel subdirectory in dist | |
| mkdir -p "dist/${CHANNEL}" | |
| cp -r "${FRONTEND_DIR}/"* "dist/${CHANNEL}/" | |
| # Create version.json for the channel | |
| cat > "dist/${CHANNEL}/version.json" << EOF | |
| { | |
| "channel": "${CHANNEL}", | |
| "frontend_version": "${FRONTEND_VERSION}", | |
| "deployed_at": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" | |
| } | |
| EOF | |
| echo "Frontend deployed to dist/${CHANNEL}/" | |
| ls -la "dist/${CHANNEL}/" | |
| - name: Download other channel builds from GitHub releases | |
| continue-on-error: true | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| CURRENT_CHANNEL="${{ steps.params.outputs.channel }}" | |
| # Read channels.json to get versions for other channels | |
| for channel in stable beta nightly; do | |
| if [ "$channel" = "$CURRENT_CHANNEL" ]; then | |
| echo "Skipping ${channel} - we're deploying this one" | |
| continue | |
| fi | |
| # Get version from channels.json | |
| VERSION=$(jq -r --arg ch "$channel" '.[$ch] // empty' channels.json) | |
| if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then | |
| echo "No version configured for ${channel}, skipping" | |
| continue | |
| fi | |
| echo "Downloading ${channel} frontend v${VERSION}..." | |
| # Create temp directory | |
| mkdir -p "/tmp/${channel}" | |
| # Download the wheel from GitHub releases | |
| WHEEL_NAME="music_assistant_frontend-${VERSION}-py3-none-any.whl" | |
| if gh release download "${VERSION}" \ | |
| --repo music-assistant/frontend \ | |
| --pattern "${WHEEL_NAME}" \ | |
| --dir "/tmp/${channel}" 2>/dev/null; then | |
| # Extract the wheel | |
| unzip -q "/tmp/${channel}/${WHEEL_NAME}" -d "/tmp/${channel}/extracted" | |
| # Copy to channel subdirectory | |
| mkdir -p "dist/${channel}" | |
| cp -r "/tmp/${channel}/extracted/music_assistant_frontend/"* "dist/${channel}/" | |
| # Create version.json | |
| cat > "dist/${channel}/version.json" << EOF | |
| { | |
| "channel": "${channel}", | |
| "frontend_version": "${VERSION}", | |
| "deployed_at": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" | |
| } | |
| EOF | |
| echo "Restored ${channel} build (v${VERSION})" | |
| else | |
| echo "Failed to download ${channel} frontend v${VERSION}" | |
| fi | |
| done | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: dist/ | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| - name: Output deployment info | |
| run: | | |
| echo "Deployed channel: ${{ steps.params.outputs.channel }}" | |
| echo "Frontend version: ${{ steps.params.outputs.frontend_version }}" | |
| echo "URL: ${{ steps.deployment.outputs.page_url }}${{ steps.params.outputs.channel }}/" |