Skip to content

Update versions.json for versionSelector in StarLight #35

Update versions.json for versionSelector in StarLight

Update versions.json for versionSelector in StarLight #35

name: Deploy to releases.slint.dev
on:
push:
paths: 'releases/**'
workflow_dispatch:
inputs:
new_release:
description: "Is this a new release? True means Cloudflare redirects will be updated and Docs will be scraped"
required: true
default: false
type: boolean
jobs:
build-and-deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./releases
outputs:
version: ${{ steps.identify-version.outputs.VERSION }}
steps:
- name: Repository Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
releases
- name: Identify Version
id: identify-version
run: |
version=$(sed -n '1p' versions.txt)
echo "VERSION=$version" >> "$GITHUB_OUTPUT"
- name: npm install
run: |
npm install
- name: Generate a token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.READ_WRITE_APP_ID }}
private-key: ${{ secrets.READ_WRITE_PRIVATE_KEY }}
repositories: website
- name: Clone website directory
uses: actions/checkout@v4
with:
repository: slint-ui/website
ref: prod
path: releases/website
token: ${{ steps.app-token.outputs.token }}
- name: Generate docs.html and 404.html
run: |
mkdir -p website/output
cd website && go run generator/generator.go -skip-agreements
- name: Copy docs.html and 404.html
run: |
cp website/output/docs.html index.html
cp website/output/404.html 404.html
rm -rf website
- name: Install Netlify
run: |
npm install netlify-cli --save-dev
- name: Install Dependencies
run: |
npm ci
- name: Deploy to Netlify
id: netlify_deploy
run: |
netlify deploy \
--dir . \
--site ${{ secrets.NETLIFY_RELEASES_SITE_ID }} \
--auth ${{ secrets.NETLIFY_API_TOKEN }} \
--prod
- name: Set environment variables
run: |
echo "CLOUDFLARE_API_TOKEN=${{ secrets.CLOUDFLARE_API_TOKEN }}" >> $GITHUB_ENV
echo "CLOUDFLARE_ACCOUNT_ID=${{ secrets.CLOUDFLARE_ACCOUNT_ID }}" >> $GITHUB_ENV
- name: Copy latest release to docs
run: |
rsync -ua ${{ steps.identify-version.outputs.VERSION }} docs
cp versions.txt 404.html index.html docs
mv docs/${{ steps.identify-version.outputs.VERSION }} docs/latest
- name: Create _redirects file
run: |
echo "/demos/* /latest/demos/:splat" > docs/_redirects
echo "/docs/* /latest/docs/:splat" >> docs/_redirects
echo "/editor/* /latest/editor/:splat" >> docs/_redirects
echo "/${{ steps.identify-version.outputs.VERSION }}/* /latest/:splat" >> docs/_redirects
echo "/ /latest/docs/slint/" >> docs/_redirects
echo "/latest/docs/ /latest/docs/slint/" >> docs/_redirects
- name: Verify _redirects file
run: cat docs/_redirects
- name: Create headers file
run: |
echo "/*" > docs/_headers
echo " Access-Control-Allow-Origin: *" >> docs/_headers
- name: Verify _headers file
run: cat docs/_headers
- name: Publish latest release to docs
run: |
cd docs && npx wrangler@3 pages deploy . --project-name=docs --commit-dirty=true
- name: Update Cloudflare redirects to prefer docs.slint.dev
if: ${{ github.event.inputs.new_release == 'true' }}
run: |
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/${{ vars.CLOUDFLARE_ZONE_ID }}/rulesets/${{ vars.CLOUDFLARE_RULESET_ID }}/rules/${{ vars.CLOUDFLARE_RULE_ID }}" \
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
-H 'Content-Type: application/json' \
-d '{
"position": {
"before": "${{ vars.CLOUDFLARE_BEFORE_RULE_ID }}"
},
"action": "redirect",
"action_parameters": {
"from_value": {
"status_code": 301,
"target_url": {
"expression": "concat(\"https://releases.slint.dev\", http.request.uri.path)"
},
"preserve_query_string": true
}
},
"description": "docs.slint.dev to releases subdomain",
"enabled": false,
"expression": "(http.host eq \"docs.slint.dev\" and not starts_with(http.request.uri.path, \"/${{ steps.identify-version.outputs.VERSION }}\") and http.request.uri ne \"/index.html\" and http.request.uri ne \"/\") and not starts_with(http.request.uri.path, \"/latest\")",
"id": "${{ vars.CLOUDFLARE_RULE_ID }}",
"ref": "${{ vars.CLOUDFLARE_RULE_ID }}"
}'
# scrape-docs:
# if: ${{ github.event.inputs.new_release == 'true' }}
# uses: ./.github/workflows/docsearch-scrape.yml
# needs: build-and-deploy
# secrets: inherit
# with:
# version: ${{ needs.build-and-deploy.outputs.version }}