|
| 1 | +name: Publish Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | + |
| 9 | +jobs: |
| 10 | + |
| 11 | + |
| 12 | +# ============================================================================= |
| 13 | +# Build |
| 14 | +# ============================================================================= |
| 15 | + |
| 16 | + build: |
| 17 | + |
| 18 | + name: Build |
| 19 | + |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + |
| 24 | + |
| 25 | + - |
| 26 | + name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - |
| 30 | + name: Setup Node |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: 18.x |
| 34 | + |
| 35 | + # - name: Check if version has been updated |
| 36 | + # id: check |
| 37 | + # uses: EndBug/version-check@v2 |
| 38 | + |
| 39 | + - |
| 40 | + name: NPM Install |
| 41 | + # if: steps.check.outputs.changed == 'true' |
| 42 | + run: | |
| 43 | + npm clean-install |
| 44 | +
|
| 45 | + # - |
| 46 | + # name: NPM Run Lint |
| 47 | + # run: | |
| 48 | + # npm run lint --if-present |
| 49 | + |
| 50 | + - |
| 51 | + name: NPM Run Test |
| 52 | + run: | |
| 53 | + npm run test --if-present |
| 54 | +
|
| 55 | + - |
| 56 | + name: NPM Run Build |
| 57 | + run: | |
| 58 | + npm run build --if-present |
| 59 | +
|
| 60 | + - |
| 61 | + name: Zip dist & node_modules |
| 62 | + run: zip -9qry "build.zip" "./" -i "node_modules/*" -i "dist/*" |
| 63 | + |
| 64 | + - |
| 65 | + name: Upload build.zip |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: build.zip |
| 69 | + path: build.zip |
| 70 | + |
| 71 | + |
| 72 | +# ============================================================================= |
| 73 | +# Create a GitHub Release |
| 74 | +# ============================================================================= |
| 75 | + |
| 76 | + release: |
| 77 | + |
| 78 | + name: Create GitHub Release |
| 79 | + |
| 80 | + needs: build |
| 81 | + |
| 82 | + runs-on: ubuntu-latest |
| 83 | + |
| 84 | + steps: |
| 85 | + |
| 86 | + - |
| 87 | + name: Checkout |
| 88 | + uses: actions/checkout@master |
| 89 | + |
| 90 | + - |
| 91 | + name: Download build.zip |
| 92 | + uses: actions/download-artifact@v4 |
| 93 | + with: |
| 94 | + name: build.zip |
| 95 | + |
| 96 | + - |
| 97 | + name: Create Release |
| 98 | + id: create_release |
| 99 | + uses: actions/create-release@v1 |
| 100 | + env: |
| 101 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + with: |
| 103 | + tag_name: ${{ github.ref }} |
| 104 | + release_name: Release ${{ github.ref }} |
| 105 | + |
| 106 | + - |
| 107 | + name: Upload Release Asset |
| 108 | + uses: actions/upload-release-asset@v1 |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + with: |
| 112 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 113 | + asset_path: ./build.zip |
| 114 | + asset_name: build.zip |
| 115 | + asset_content_type: application/zip |
| 116 | + |
| 117 | + |
| 118 | +# ============================================================================= |
| 119 | +# Publish to NPM |
| 120 | +# ============================================================================= |
| 121 | + |
| 122 | + publish-npm: |
| 123 | + |
| 124 | + name: Publish NPM |
| 125 | + |
| 126 | + needs: build |
| 127 | + |
| 128 | + runs-on: ubuntu-latest |
| 129 | + |
| 130 | + steps: |
| 131 | + |
| 132 | + - |
| 133 | + name: Checkout |
| 134 | + uses: actions/checkout@v4 |
| 135 | + |
| 136 | + - |
| 137 | + name: Setup Node |
| 138 | + uses: actions/setup-node@v4 |
| 139 | + with: |
| 140 | + node-version: 18.x |
| 141 | + registry-url: https://registry.npmjs.org/ |
| 142 | + |
| 143 | + - |
| 144 | + name: Download build.zip |
| 145 | + uses: actions/download-artifact@v4 |
| 146 | + with: |
| 147 | + name: build.zip |
| 148 | + |
| 149 | + - |
| 150 | + name: Unzip build.zip |
| 151 | + run: unzip -q -o build.zip |
| 152 | + |
| 153 | + - |
| 154 | + name: Publish NPM |
| 155 | + run: | |
| 156 | + cd dist |
| 157 | + npm publish --access public |
| 158 | + env: |
| 159 | + NODE_AUTH_TOKEN: ${{secrets.PUBLISH_NPM_TOKEN}} |
| 160 | + |
| 161 | + |
| 162 | +# ============================================================================= |
| 163 | +# Publish to GitHub Packages |
| 164 | +# ============================================================================= |
| 165 | + |
| 166 | + # publish-gpr: |
| 167 | + |
| 168 | + # needs: build |
| 169 | + |
| 170 | + # runs-on: ubuntu-latest |
| 171 | + |
| 172 | + # permissions: |
| 173 | + # contents: read |
| 174 | + # packages: write |
| 175 | + |
| 176 | + # steps: |
| 177 | + |
| 178 | + # - |
| 179 | + # # uses: actions/checkout@v4 |
| 180 | + # uses: actions/checkout@v4 |
| 181 | + |
| 182 | + # - |
| 183 | + # uses: actions/setup-node@v4 |
| 184 | + # with: |
| 185 | + # # node-version: 16 |
| 186 | + # node-version: 18 |
| 187 | + # registry-url: https://npm.pkg.github.com/ |
| 188 | + # # scope: '@scape-agency' |
| 189 | + |
| 190 | + # - |
| 191 | + # name: Download build.zip |
| 192 | + # uses: actions/download-artifact@v4 |
| 193 | + # with: |
| 194 | + # name: build.zip |
| 195 | + |
| 196 | + # - |
| 197 | + # name: Unzip build.zip |
| 198 | + # run: unzip -q build.zip |
| 199 | + |
| 200 | + # - |
| 201 | + # run: npm publish |
| 202 | + # env: |
| 203 | + # NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
0 commit comments