|
| 1 | +name: Publish Releases |
| 2 | +run-name: Publish Releases |
| 3 | + |
| 4 | +permissions: |
| 5 | + contents: write |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + publish_to_github: |
| 11 | + description: 'Publish to GitHub Release' |
| 12 | + required: false |
| 13 | + default: 'false' |
| 14 | + type: boolean |
| 15 | + publish_to_npm: |
| 16 | + description: 'Publish to npm' |
| 17 | + required: false |
| 18 | + default: 'false' |
| 19 | + type: boolean |
| 20 | + github_tag: |
| 21 | + description: 'Release tag for GitHub (e.g., v1.0.0)' |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + github_release_notes: |
| 25 | + description: 'Release notes for GitHub' |
| 26 | + required: false |
| 27 | + type: string |
| 28 | + npm_version: |
| 29 | + description: 'npm package version (e.g., 1.0.0)' |
| 30 | + required: false |
| 31 | + type: string |
| 32 | + npm_release_notes: |
| 33 | + description: 'Release notes for npm' |
| 34 | + required: false |
| 35 | + type: string |
| 36 | + |
| 37 | +jobs: |
| 38 | + publish_github_release: |
| 39 | + name: Publish to GitHub Release |
| 40 | + if: ${{ github.event.inputs.publish_to_github == 'true' }} |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - name: Checkout code |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Setup Node.js |
| 47 | + uses: actions/setup-node@v4 |
| 48 | + with: |
| 49 | + node-version: "22.4.1" |
| 50 | + |
| 51 | + - name: Install Dependencies |
| 52 | + run: npm ci |
| 53 | + |
| 54 | + - name: Create GitHub Release |
| 55 | + id: create_release |
| 56 | + |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + with: |
| 60 | + tag_name: ${{ github.event.inputs.github_tag }} |
| 61 | + release_name: Release ${{ github.event.inputs.github_tag }} |
| 62 | + body: ${{ github.event.inputs.github_release_notes }} |
| 63 | + draft: false |
| 64 | + prerelease: false |
| 65 | + |
| 66 | + - name: Package Plugin |
| 67 | + id: package_plugin |
| 68 | + run: | |
| 69 | + npm pack |
| 70 | + echo "PACKAGE_NAME=$(ls *.tgz)" >> $GITHUB_ENV |
| 71 | +
|
| 72 | + - name: Upload Release Asset |
| 73 | + if: ${{ github.event.inputs.github_tag }} |
| 74 | + |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + with: |
| 78 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 79 | + asset_path: ${{ env.PACKAGE_NAME }} |
| 80 | + asset_name: ${{ env.PACKAGE_NAME }} |
| 81 | + asset_content_type: application/gzip |
| 82 | + |
| 83 | + publish_npm_release: |
| 84 | + name: Publish to npm |
| 85 | + if: ${{ github.event.inputs.publish_to_npm == 'true' }} |
| 86 | + runs-on: ubuntu-latest |
| 87 | + steps: |
| 88 | + - name: Checkout code |
| 89 | + uses: actions/checkout@v4 |
| 90 | + |
| 91 | + - name: Setup Node.js |
| 92 | + uses: actions/setup-node@v4 |
| 93 | + with: |
| 94 | + node-version: "22.4.1" |
| 95 | + |
| 96 | + - name: Install Dependencies |
| 97 | + run: npm ci |
| 98 | + |
| 99 | + - name: Build Project |
| 100 | + run: npm run build --if-present |
| 101 | + |
| 102 | + - name: Update package version |
| 103 | + if: ${{ github.event.inputs.npm_version }} |
| 104 | + run: | |
| 105 | + npm version ${{ github.event.inputs.npm_version }} --no-git-tag-version |
| 106 | + git config --global user.email "${{ secrets.GIT_USER_EMAIL }}" |
| 107 | + git config --global user.name "${{ secrets.GIT_USER_NAME }}" |
| 108 | + git add package.json |
| 109 | + git commit -m "chore: release version ${{ github.event.inputs.npm_version }}" |
| 110 | + git push |
| 111 | +
|
| 112 | + - name: Publish to npm |
| 113 | + run: npm publish |
| 114 | + env: |
| 115 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments