|
| 1 | +name: Build & Release Hopkit |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + paths: |
| 7 | + - 'package.json' |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + include: |
| 14 | + - platform: win |
| 15 | + runs-on: windows-latest |
| 16 | + - platform: mac |
| 17 | + runs-on: macos-latest |
| 18 | + - platform: linux |
| 19 | + runs-on: ubuntu-latest |
| 20 | + runs-on: ${{ matrix.runs-on }} |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Get version |
| 28 | + id: get_version |
| 29 | + run: echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_ENV |
| 30 | + |
| 31 | + - name: Setup Node.js |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: '20' |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: npm ci |
| 38 | + |
| 39 | + - name: Build for ${{ matrix.platform }} |
| 40 | + run: npm run build:${{ matrix.platform }} |
| 41 | + |
| 42 | + - name: Package build into zip (non-Windows) |
| 43 | + if: matrix.platform != 'win' |
| 44 | + run: | |
| 45 | + mkdir -p dist |
| 46 | + zip -r "dist/hopkit-${{ matrix.platform }}-v${{ env.VERSION }}.zip" "dist/${{ matrix.platform }}" || (ls -la dist && false) |
| 47 | +
|
| 48 | + - name: Package build into zip (Windows) |
| 49 | + if: matrix.platform == 'win' |
| 50 | + shell: pwsh |
| 51 | + run: | |
| 52 | + New-Item -ItemType Directory -Force -Path dist | Out-Null |
| 53 | + $src = "dist\\win\\*" |
| 54 | + $dst = "dist\\hopkit-win-v${env:VERSION}.zip" |
| 55 | + if (Test-Path $src) { |
| 56 | + Compress-Archive -Path $src -DestinationPath $dst -Force |
| 57 | + } else { |
| 58 | + Get-ChildItem -Path dist -Recurse | Format-List |
| 59 | + exit 1 |
| 60 | + } |
| 61 | +
|
| 62 | + - name: Upload artifact (zip) |
| 63 | + uses: actions/upload-artifact@v4 |
| 64 | + with: |
| 65 | + name: hopkit-${{ matrix.platform }} |
| 66 | + path: dist/hopkit-${{ matrix.platform }}-v${{ env.VERSION }}.zip |
| 67 | + |
| 68 | + publish: |
| 69 | + needs: build |
| 70 | + runs-on: ubuntu-latest |
| 71 | + permissions: |
| 72 | + contents: write |
| 73 | + steps: |
| 74 | + - name: Checkout (for version) |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Get version (publish) |
| 80 | + id: get_version_publish |
| 81 | + run: echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_ENV |
| 82 | + |
| 83 | + - name: Download Windows artifact |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + name: hopkit-win |
| 87 | + path: ./artifacts |
| 88 | + |
| 89 | + - name: Download macOS artifact |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: hopkit-mac |
| 93 | + path: ./artifacts |
| 94 | + |
| 95 | + - name: Download Linux artifact |
| 96 | + uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + name: hopkit-linux |
| 99 | + path: ./artifacts |
| 100 | + |
| 101 | + - name: Create GitHub release |
| 102 | + id: create_release |
| 103 | + uses: actions/create-release@v1 |
| 104 | + with: |
| 105 | + tag_name: v${{ env.VERSION }} |
| 106 | + release_name: Hopkit v${{ env.VERSION }} |
| 107 | + draft: false |
| 108 | + prerelease: false |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + |
| 112 | + - name: Upload Windows build to release |
| 113 | + if: always() |
| 114 | + uses: actions/upload-release-asset@v1 |
| 115 | + with: |
| 116 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 117 | + asset_path: ./artifacts/hopkit-win/hopkit-win-v${{ env.VERSION }}.zip |
| 118 | + asset_name: hopkit-win-v${{ env.VERSION }}.zip |
| 119 | + asset_content_type: application/zip |
| 120 | + |
| 121 | + - name: Upload macOS build to release |
| 122 | + if: always() |
| 123 | + uses: actions/upload-release-asset@v1 |
| 124 | + with: |
| 125 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 126 | + asset_path: ./artifacts/hopkit-mac/hopkit-mac-v${{ env.VERSION }}.zip |
| 127 | + asset_name: hopkit-mac-v${{ env.VERSION }}.zip |
| 128 | + asset_content_type: application/zip |
| 129 | + |
| 130 | + - name: Upload Linux build to release |
| 131 | + if: always() |
| 132 | + uses: actions/upload-release-asset@v1 |
| 133 | + with: |
| 134 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 135 | + asset_path: ./artifacts/hopkit-linux/hopkit-linux-v${{ env.VERSION }}.zip |
| 136 | + asset_name: hopkit-linux-v${{ env.VERSION }}.zip |
| 137 | + asset_content_type: application/zip |
0 commit comments