name: Build & Deploy pages

on:
  push:
    branches: [ "main" ]
    paths-ignore:
    - 'README.md'
    - '.gitignore'
    - '*.sh'
    - '.vscode/**'
  
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

permissions:
  id-token: write
  pages: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    
    - name: Install wasm-pack
      run: cargo install wasm-pack
      
    - name: Build
      run: wasm-pack build --target web
    
    - name: Copy index.html
      run: sed 's/.\/pkg/./g' index.html > pkg/index.html
      
    - name: Upload GitHub Pages artifact
      uses: actions/upload-pages-artifact@v1.0.7
      with:
        path: pkg/
    
    - name: Deploy GitHub Pages site
      uses: actions/deploy-pages@v1.2.3
