name: Tag

on:
  workflow_dispatch:
    inputs:
      version:
        description: Version
        required: true
      tag:
        description: Tag
        default: latest
        required: true

permissions: {}
jobs:
  tag-in-registry:
    name: Tagging ${{ github.event.inputs.version }} as ${{ github.event.inputs.tag }}
    environment: release
    runs-on: ubuntu-latest
    steps:
    - name: Setup Node
      uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
    - name: Update tag
      env:
        "npm_config_//registry.npmjs.org/:_authToken": ${{ secrets.NPM_TOKEN }}
      run: |
        npm dist-tag add pnpm@${{ github.event.inputs.version }} latest-10
        npm dist-tag add pnpm@${{ github.event.inputs.version }} ${{ github.event.inputs.tag }}
        npm dist-tag add @pnpm/exe@${{ github.event.inputs.version }} latest-10
        npm dist-tag add @pnpm/exe@${{ github.event.inputs.version }} ${{ github.event.inputs.tag }}

  publish-to-winget:
    runs-on: ubuntu-latest
    environment: release
    needs: tag-in-registry
    steps:
      - uses: vedantmgoyal9/winget-releaser@19e706d4c9121098010096f9c495a70a7518b30f # main
        with:
          identifier: pnpm.pnpm
          version: ${{ github.event.inputs.version }}
          release-tag: v${{ github.event.inputs.version }}
          token: ${{ secrets.WINGET_TOKEN }}

  post-to-reddit:
    runs-on: ubuntu-latest
    environment: release
    needs: tag-in-registry
    steps:
      - uses: bluwy/release-for-reddit-action@b4ee0e0d64da893e0428912aac5cda675082bd85 # v2.0.0
        with:
          username: ${{ secrets.REDDIT_USERNAME }}
          password: ${{ secrets.REDDIT_PASSWORD }}
          app-id: ${{ secrets.REDDIT_APP_ID }}
          app-secret: ${{ secrets.REDDIT_APP_SECRET }}
          subreddit: pnpm
          title: pnpm@${{ github.event.inputs.version }} is out!
          url: https://github.com/pnpm/pnpm/releases/tag/v${{ github.event.inputs.version }}

  post-to-mastodon:
    runs-on: ubuntu-latest
    environment: release
    needs: tag-in-registry
    steps:
      - name: Send toot to Mastodon
        id: mastodon
        uses: cbrgm/mastodon-github-action@96ff691bc465fd7654dfb68697f94465125a7e21 # v2.1.21
        with:
          message: |
            pnpm@${{ github.event.inputs.version }} is out!
            https://github.com/pnpm/pnpm/releases/tag/v${{ github.event.inputs.version }}
          visibility: "public"
        env:
          MASTODON_URL: "https://fosstodon.org/"
          MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} # access token

