name: Create Release

on:
  push:
    branches:
      - master

jobs:
  create_release:
    if: contains(github.event.head_commit.message, 'new release')
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18"

      - name: Install Dependencies
        run: npm install

      - name: Build
        run: npm run build

      - name: Get Release Version
        id: release-version
        run: |
          echo "VER=$(echo ${{ github.event.head_commit.message }} | cut -d' ' -f3)" >> $GITHUB_OUTPUT

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ steps.release-version.outputs.VER }}
          body: "New release ${{ steps.release-version.outputs.VER }}"
          draft: false
          prerelease: false
          files: |
            main.js
            manifest.json
            styles.css
