name: new version

on:
  push:
    tags:
      - '*.*.*'

jobs:
  build:
    name: treehouses/cli
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: https://registry.npmjs.org/
      - name: build
        run: |
          ./templates/blocker/blocker.sh
          ls -al ./templates/blocker/
          sudo npm install -g auto-changelog
          auto-changelog --version
          auto-changelog --template .github/workflows/changelog-template.hbs
          sync
          sed -i -e "s#&lt;#<#g" CHANGELOG.md
          sed -i -e "s#&gt;#>#g" CHANGELOG.md
          ls -al
      - name: release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: ${{ github.ref }}
          body: |
            ${{ github.event.head_commit.message }}
          draft: false
          prerelease: false
      - name: publish
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      - name: report
        run: |
          sudo npm install -g @treehouses/cli
          export discord_channel="${{ secrets.CHANNEL }}"
          treehouses feedback "new [treehouses/cli](https://github.com/treehouses/cli) release **[$( echo ${{ github.ref }} | cut -d'/' -f3 )](https://www.npmjs.com/package/@treehouses/cli/v/$( echo ${{ github.ref }} | cut -d'/' -f3 ))**"
