name: Deploy to neocities

# only run on changes to master
on:
  push:
    branches:
      - main

concurrency: # prevent concurrent deploys doing strange things
  group: deploy-to-neocities
  cancel-in-progress: true

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: "true"
      # Set up any tools and build steps here
      # This example uses a Node.js toolchain to build a site
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: lts/*
      - name: Install deps and build
        run: |
          npm i
          npm run build
      # When the dist_dir is ready, deploy it to neocities
      - name: Deploy to neocities
        id: deploy
        if: ${{ success() }}
        uses: bcomnes/deploy-to-neocities@v1
        continue-on-error: true
        with:
          api_token: ${{ secrets.NEOCITIES_API_TOKEN }}
          cleanup: true
          dist_dir: dist
      - name: Deploy to neocities (fallback edition)
        if: ${{ steps.deploy.outcome == 'failure' }}
        uses: jonchang/deploy-neocities@master
        with:
          key: ${{ secrets.NEOCITIES_API_TOKEN }}
          clean: true
          dir: dist
