# Copyright 2020-2022 David Sherret. All rights reserved. MIT license.
name: Package Publish

on:
  release:
    types: [published]
jobs:
  publish:
    runs-on: ubuntu-latest
    if: github.repository == 'dprint/dprint'
    steps:
    - name: Get tag version
      id: get_tag_version
      run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}

    - name: Checkout
      uses: actions/checkout@v2

      # CARGO PUBLISH
    - uses: dtolnay/rust-toolchain@stable
    - name: Cargo login
      run: cargo login ${{ secrets.CRATES_TOKEN }}

    - name: Cargo publish
      run: |
        cd crates/dprint
        cargo publish

      # NPM PUBLISH
    - uses: actions/setup-node@v2
      with:
        node-version: '16.x'
        registry-url: 'https://registry.npmjs.org'

    - name: npm publish
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      run: |
        cd deployment/npm
        curl --fail --location --progress-bar --output "SHASUMS256.txt" "https://github.com/dprint/dprint/releases/download/${{steps.get_tag_version.outputs.TAG_VERSION}}/SHASUMS256.txt"
        node setup.js ${{steps.get_tag_version.outputs.TAG_VERSION}}
        npm publish
