# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Takedown Release

on:
  # push:
  #   branches: [ "master" ]
  release:
    types: [published]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  publish:
    # if: github.ref == 'refs/heads/master'
    runs-on: ubuntu-latest
    steps:
      - name: checkout repo
        uses: actions/checkout@v4
      - name: setup node
        uses: actions/setup-node@v4
        with:
          node-version: 23
          registry-url: https://registry.npmjs.org/
      - name: install deps
        run: npm ci
      - name: test code
        run: npm test
      - name: build code
        run: npm run build
      - name: setup pages
        uses: actions/configure-pages@v5
      - name: jekyll build
        uses: actions/jekyll-build-pages@v1
        with:
          source: ./dist
          destination: ./_site
      - name: upload artifact
        uses: actions/upload-pages-artifact@v3
      - name: publish
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: publish
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
