Deploy package #3
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
| # https://docs.npmjs.com/trusted-publishers#github-actions-configuration | |
| name: Deploy package | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - "[0-9].[0-9].[0-9]" | |
| permissions: | |
| id-token: write # Required for OIDC | |
| contents: read | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: Deploy | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24.x" | |
| registry-url: "https://registry.npmjs.org" | |
| package-manager-cache: false # never use caching in release builds | |
| - name: Summary Head | |
| run: | | |
| echo "# Deployment Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "Date: $(date) " >> $GITHUB_STEP_SUMMARY | |
| echo "Run ID: ${{ github.run_id }} " >> $GITHUB_STEP_SUMMARY | |
| echo "Run Number: ${{ github.run_number }} " >> $GITHUB_STEP_SUMMARY | |
| echo "Run Attempt: ${{ github.run_attempt }} " >> $GITHUB_STEP_SUMMARY | |
| echo "Node Version: $(node --version) - NPM Version: $(npm --version) " >> $GITHUB_STEP_SUMMARY | |
| - name: Read package.json | |
| id: package-json | |
| run: | | |
| echo "PACKAGE_JSON<<GH-EOF" >> $GITHUB_ENV | |
| cat ./package.json >> $GITHUB_ENV | |
| echo "GH-EOF" >> $GITHUB_ENV | |
| - name: "Read package version" | |
| run: | | |
| version=${{ fromJson(env.PACKAGE_JSON).version }} | |
| escaped_version=$(printf '%s\n' "$version" | sed -e 's/[]\/$*.^[]/\\&/g') | |
| echo "VERSION=$version" >> $GITHUB_ENV | |
| echo "ESCAPED_VERISON=$escaped_version" >> $GITHUB_ENV | |
| echo "Package Version: **$version** " >> $GITHUB_STEP_SUMMARY | |
| - name: Install | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Lint | |
| run: npm run lint | |
| - name: Test | |
| run: npm run test | |
| - name: Publish | |
| run: | | |
| npm publish | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Successfully published to the [NPM registry](https://www.npmjs.com/package/sourcelib/v/$VERSION)" >> $GITHUB_STEP_SUMMARY | |
| - name: Get Changelog | |
| id: changelog | |
| run: | | |
| changelog=`sed -n "/^## \[$ESCAPED_VERSION]/,/^## /p" CHANGELOG.md | sed '$ d' | sed '1,1d'` | |
| changelog1="${changelog//'%'/'%25'}" | |
| changelog1="${changelog1//$'\n'/'%0A'}" | |
| changelog1="${changelog1//$'\r'/'%0D'}" | |
| changelog2="${changelog//$'\n'/'\\n'}" | |
| changelog2="${changelog2//$'\r'/'\\r'}" | |
| changelog2="${changelog2//$'('/'\('}" | |
| changelog2="${changelog2//$')'/'\)'}" | |
| changelog2="${changelog2//$'`'/'\`'}" | |
| changelog2="${changelog2//$'"'/'\"'}" | |
| changelog2="${changelog2//"'"/"'\''"}" | |
| echo "CL_ESCAPED=$changelog" >> $GITHUB_ENV | |
| echo "CL_UNESCAPED=$changelog1" >> $GITHUB_ENV | |
| echo "CL_DOUBLEESCAPED=$changelog2" >> $GITHUB_ENV | |
| - name: Github Release | |
| id: release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| body: "${{env.CL_UNESCAPED}}" | |
| tag_name: "${{env.VERSION}}" | |
| - name: Prepare Discord Message | |
| id: discord-msg | |
| working-directory: ./ | |
| run: | | |
| awk '{ | |
| gsub("#VERSION#","${{env.VERSION}}",$0); | |
| gsub("#DESCRIPTION#","${{env.CL_DOUBLEESCAPED}}",$0); | |
| print $0; | |
| }' ./.github/workflows/deploy_discord_message.json > ./.github/workflows/deploy_discord_message2.json | |
| - name: Send Discord Message | |
| uses: tsickert/discord-webhook@v4.0.0 | |
| # working-directory: ./ | |
| with: | |
| webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| raw-data: "./.github/workflows/deploy_discord_message2.json" | |
| - name: Summary Footer | |
| run: | | |
| echo "Created GitHub [Release](https://github.com/SecondFaceSoftware/sourcelib/releases/tag/${{env.VERSION}})" >> $GITHUB_STEP_SUMMARY | |
| echo "Discord Message sent successfully" >> $GITHUB_STEP_SUMMARY |