name: '[CI] Build Release'

on:
    push:
        tags:
        -   '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]+'  # YYYY.MM.MICRO

env:
    MINICONDA_PYTHON_VERSION: py38
    MINICONDA_VERSION: 4.11.0

defaults:
    run:
        working-directory: pyscriptjs

jobs:
    build:
        runs-on: ubuntu-latest
        steps:

        -   name: Checkout
            uses: actions/checkout@v3

        -   name: Install node
            uses: actions/setup-node@v3
            with:
                node-version: 18.x

        -   name: Cache node modules
            uses: actions/cache@v3
            env:
                cache-name: cache-node-modules
            with:
              # npm cache files are stored in `~/.npm` on Linux/macOS
                path: ~/.npm
                key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
                restore-keys: |
                    ${{ runner.os }}-build-${{ env.cache-name }}-
                    ${{ runner.os }}-build-
                    ${{ runner.os }}-

        -   name: setup Miniconda
            uses: conda-incubator/setup-miniconda@v2

        -   name: Setup Environment
            run: make setup

        -   name: Build and Test
            run: make test

        -   name: Prepare Release
            uses: softprops/action-gh-release@v1
            with:
                draft: true
                prerelease: true
                generate_release_notes: true
