Update RSS Readers (ALL) in production #12
Workflow file for this run
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: Update RSS Reader Apps | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| app_key: | |
| description: "App key (leave empty to update ALL apps, or enter one key like 'bbc-news')" | |
| required: false | |
| type: string | |
| override_app_name: | |
| description: 'Override app name (optional, leave empty to use deployed-apps.yml)' | |
| required: false | |
| type: string | |
| override_description: | |
| description: 'Override app description (optional, leave empty to use deployed-apps.yml)' | |
| required: false | |
| type: string | |
| override_rss_title: | |
| description: 'Override RSS title (optional, leave empty to use deployed-apps.yml)' | |
| required: false | |
| type: string | |
| override_icon_url: | |
| description: 'Override icon URL (optional, leave empty to use deployed-apps.yml)' | |
| required: false | |
| type: string | |
| override_rss_url: | |
| description: 'Override RSS URL (optional, leave empty to use deployed-apps.yml)' | |
| required: false | |
| type: string | |
| run-name: Update RSS Reader${{ inputs.app_key && format(' - {0}', inputs.app_key) || 's (ALL)' }} in ${{ startsWith(github.ref, 'refs/tags/v') && 'production' || 'stage' }} | |
| jobs: | |
| prepare: | |
| name: Prepare App Matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| app_count: ${{ steps.set-matrix.outputs.app_count }} | |
| environment: ${{ steps.set-env.outputs.environment }} | |
| api_base_url: ${{ steps.set-env.outputs.api_base_url }} | |
| manifest_file_name: ${{ steps.set-env.outputs.manifest_file_name }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set environment | |
| id: set-env | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| echo "environment=production" >> "$GITHUB_OUTPUT" | |
| echo "api_base_url=https://api.screenlyapp.com" >> "$GITHUB_OUTPUT" | |
| echo "manifest_file_name=screenly.yml" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "environment=stage" >> "$GITHUB_OUTPUT" | |
| echo "api_base_url=https://api.screenlyappstage.com" >> "$GITHUB_OUTPUT" | |
| echo "manifest_file_name=screenly_qc.yml" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Setup yq | |
| uses: ./.github/actions/setup-yq | |
| - name: Generate App Matrix | |
| id: set-matrix | |
| run: | | |
| CONFIG_FILE="./deployed-apps.yml" | |
| APP_KEY_INPUT="${{ inputs.app_key }}" | |
| ENVIRONMENT="${{ steps.set-env.outputs.environment }}" | |
| if [ -n "$APP_KEY_INPUT" ]; then | |
| if ! yq ".apps.$APP_KEY_INPUT" "$CONFIG_FILE" | grep -q "ids:" || \ | |
| [ "$(yq -r ".apps.$APP_KEY_INPUT.ids | has(\"$ENVIRONMENT\")" "$CONFIG_FILE")" != "true" ]; then | |
| echo "Error: App key '$APP_KEY_INPUT' missing 'ids.$ENVIRONMENT'" | |
| exit 1 | |
| fi | |
| MATRIX=$(yq -o=json -I=0 '.apps | to_entries | map(select(.key == "'"$APP_KEY_INPUT"'") | {"key": .key, "id": .value.ids.'"$ENVIRONMENT"'})' "$CONFIG_FILE") | |
| APP_COUNT=1 | |
| else | |
| MATRIX=$(yq -o=json -I=0 '.apps | to_entries | map(select(.value.ids and (.value.ids | has("'"$ENVIRONMENT"'"))) | {"key": .key, "id": .value.ids.'"$ENVIRONMENT"'})' "$CONFIG_FILE") | |
| APP_COUNT=$(echo "$MATRIX" | yq 'length') | |
| if [ "$APP_COUNT" -eq 0 ]; then | |
| echo "No apps found with IDs configured for environment: $ENVIRONMENT" | |
| exit 1 | |
| fi | |
| fi | |
| echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT" | |
| echo "app_count=$APP_COUNT" >> "$GITHUB_OUTPUT" | |
| deploy: | |
| name: Update ${{ matrix.app.key }} | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| if: needs.prepare.outputs.app_count > 0 | |
| environment: ${{ needs.prepare.outputs.environment }} | |
| strategy: | |
| matrix: | |
| app: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
| fail-fast: false | |
| env: | |
| API_BASE_URL: ${{ needs.prepare.outputs.api_base_url }} | |
| MANIFEST_FILE_NAME: ${{ needs.prepare.outputs.manifest_file_name }} | |
| SCREENLY_API_TOKEN: ${{ secrets.SCREENLY_API_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup yq | |
| uses: ./.github/actions/setup-yq | |
| - name: Update manifest from config | |
| run: | | |
| CONFIG_FILE="./deployed-apps.yml" | |
| APP_ID="${{ matrix.app.id }}" | |
| APP_KEY="${{ matrix.app.key }}" | |
| CONFIG_APP_NAME=$(yq ".apps.$APP_KEY.app_name" "$CONFIG_FILE") | |
| CONFIG_DESC=$(yq ".apps.$APP_KEY.description" "$CONFIG_FILE") | |
| CONFIG_RSS_TITLE=$(yq ".apps.$APP_KEY.rss_title" "$CONFIG_FILE") | |
| CONFIG_ICON=$(yq ".apps.$APP_KEY.icon_url" "$CONFIG_FILE") | |
| CONFIG_RSS_URL=$(yq ".apps.$APP_KEY.rss_url" "$CONFIG_FILE") | |
| FINAL_APP_NAME="${{ inputs.override_app_name }}" | |
| [ -z "$FINAL_APP_NAME" ] && FINAL_APP_NAME="$CONFIG_APP_NAME" | |
| FINAL_DESC="${{ inputs.override_description }}" | |
| [ -z "$FINAL_DESC" ] && FINAL_DESC="$CONFIG_DESC" | |
| FINAL_RSS_TITLE="${{ inputs.override_rss_title }}" | |
| [ -z "$FINAL_RSS_TITLE" ] && FINAL_RSS_TITLE="$CONFIG_RSS_TITLE" | |
| FINAL_ICON="${{ inputs.override_icon_url }}" | |
| [ -z "$FINAL_ICON" ] && FINAL_ICON="$CONFIG_ICON" | |
| FINAL_RSS_URL="${{ inputs.override_rss_url }}" | |
| [ -z "$FINAL_RSS_URL" ] && FINAL_RSS_URL="$CONFIG_RSS_URL" | |
| yq -i '.id = "'"$APP_ID"'"' "$MANIFEST_FILE_NAME" | |
| yq -i '.description = "'"$FINAL_DESC"'"' "$MANIFEST_FILE_NAME" | |
| yq -i '.icon = "'"$FINAL_ICON"'"' "$MANIFEST_FILE_NAME" | |
| yq -i '.settings.rss_url.default_value = "'"$FINAL_RSS_URL"'"' "$MANIFEST_FILE_NAME" | |
| yq -i '.settings.rss_title.default_value = "'"$FINAL_RSS_TITLE"'"' "$MANIFEST_FILE_NAME" | |
| - name: Show updated manifest | |
| run: cat "$MANIFEST_FILE_NAME" | |
| - name: Set up Bun | |
| uses: oven-sh/setup-bun@v2 | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Build | |
| run: bun run build | |
| - name: Deploy Edge App | |
| uses: screenly/cli@master | |
| with: | |
| screenly_api_token: ${{ env.SCREENLY_API_TOKEN }} | |
| cli_commands: edge-app deploy --path="./dist" --delete-missing-settings=true | |
| summary: | |
| name: Deployment Summary | |
| needs: [prepare, deploy] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Summary | |
| run: | | |
| echo "Environment: ${{ needs.prepare.outputs.environment }}" | |
| echo "Apps processed: ${{ needs.prepare.outputs.app_count }}" | |
| echo "Deployment status: ${{ needs.deploy.result }}" |