name: Release Job
run-name: ${{gitea.actor}} is releasing a package
on:
  release:
    types: [ published ]

jobs:
  build:
    runs-on: node-01
    permissions:
      contents: write
    steps:
      - name: Print Tag
        run: |
          echo ${{github.ref_name}}
          echo ${GITHUB_REF##*/}

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '18'  # Specify the Node.js version you need

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

      - name: Build project
        env:
          VERSION: ${{github.ref_name}}
        run: npm run build

      - name: Package build output
        run: |
          cd ./dist
          zip -r release.zip .  # Adjust the path to your build output directory
          mv release.zip /tmp/release.zip

      - name: Auto Commit
        run: |
          git add .
          git commit -m "auto commit"
          git push origin HEAD:main

      - name: Package Upload
        uses: akkuman/gitea-release-action@v1
        with:
          server_url: https://git.macniel.online
          files: |
            /tmp/release.zip