1.5.7 #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to NPM | |
| on: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - 'package.json' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if version changed | |
| id: version-check | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| git checkout HEAD~1 -- package.json 2>/dev/null || echo "First commit" | |
| PREVIOUS_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0") | |
| git checkout HEAD -- package.json | |
| echo "Current version: $CURRENT_VERSION" | |
| echo "Previous version: $PREVIOUS_VERSION" | |
| if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then | |
| echo "version_changed=true" >> $GITHUB_OUTPUT | |
| echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| else | |
| echo "version_changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Node.js | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| registry-url: 'https://registry.npmjs.org' | |
| always-auth: true | |
| - name: Fix package.json (optional) | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| run: npm pkg fix || true | |
| - name: Install dependencies | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| run: | | |
| # Use npm ci when a lockfile exists for reproducible installs; otherwise fall back to npm install | |
| if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then | |
| npm ci | |
| else | |
| npm install | |
| fi | |
| - name: Run tests | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| run: npm test | |
| - name: Create Git Tag | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "v${{ steps.version-check.outputs.new_version }}" -m "Release v${{ steps.version-check.outputs.new_version }}" | |
| git push origin "v${{ steps.version-check.outputs.new_version }}" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build release tarball (npm pack) | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| id: build_release | |
| run: | | |
| npm pkg fix || true | |
| TARFILE=$(npm pack) | |
| echo "tarfile=$TARFILE" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| with: | |
| tag_name: "v${{ steps.version-check.outputs.new_version }}" | |
| release_name: "v${{ steps.version-check.outputs.new_version }}" | |
| body: "Automated release for v${{ steps.version-check.outputs.new_version }}" | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload release asset | |
| if: steps.version-check.outputs.version_changed == 'true' | |
| uses: actions/upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ${{ steps.build_release.outputs.tarfile }} | |
| asset_name: discord-dm-manager-${{ steps.version-check.outputs.new_version }}.tgz | |
| asset_content_type: application/gzip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |