name: CI
on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 14

      - run: npm i markdown-to-html-cli -g
      - run: mkdir build
      - run: markdown-to-html --output build/index.html

      - run: cp -rp example/*html build

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./build

      - name: Create Tag
        id: create_tag
        uses: jaywcjlove/create-tag-action@v1.3.5
        with:
          package-path: ./package.json

      - name: Generate Changelog
        id: changelog
        uses: jaywcjlove/changelog-generator@v1.4.8
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          head-ref: ${{steps.create_tag.outputs.version}}
          filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'

      - name: Create Release
        uses: ncipollo/release-action@v1
        if: steps.create_tag.outputs.successful
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          name: ${{ steps.create_tag.outputs.version }}
          tag: ${{ steps.create_tag.outputs.version }}
          body: |
            ${{ steps.changelog.outputs.compareurl }}

            ${{ steps.changelog.outputs.changelog }}

      - name: 📦 parcel-transformer-markdown publish to NPM
        uses: JS-DevTools/npm-publish@v1
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./package.json