|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + name: Release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + published: ${{ steps.changesets.outputs.published }} |
| 16 | + publishedPackages: ${{ steps.changesets.outputs.publishedPackages }} |
| 17 | + env: |
| 18 | + COREPACK_ENABLE_STRICT: 0 |
| 19 | + steps: |
| 20 | + - name: Checkout Repo |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Install pnpm |
| 24 | + run: | |
| 25 | + corepack enable |
| 26 | + corepack prepare pnpm@latest --activate |
| 27 | +
|
| 28 | + - name: Install Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: 22 |
| 32 | + cache: pnpm |
| 33 | + |
| 34 | + - name: Install Dependencies |
| 35 | + env: |
| 36 | + SKIP_RUST_BUILD: 1 |
| 37 | + run: pnpm install |
| 38 | + |
| 39 | + - name: Create Release Pull Request or Publish to npm |
| 40 | + id: changesets |
| 41 | + uses: changesets/action@v1 |
| 42 | + with: |
| 43 | + publish: pnpm release |
| 44 | + env: |
| 45 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 47 | + |
| 48 | + - name: Check object |
| 49 | + run: | |
| 50 | + cat << OBJECT |
| 51 | + ${{ toJson(steps.changesets.outputs) }} |
| 52 | + OBJECT |
| 53 | +
|
| 54 | + release-binaries: |
| 55 | + needs: release |
| 56 | + if: needs.release.outputs.published == 'true' |
| 57 | + name: Build binaries for ${{matrix.target}} |
| 58 | + runs-on: ${{matrix.runner}} |
| 59 | + env: |
| 60 | + PUBLISHED_VERSION: ${{ fromJson(needs.release.outputs.publishedPackages)[0].version }} |
| 61 | + COREPACK_ENABLE_STRICT: 0 |
| 62 | + strategy: |
| 63 | + fail-fast: false |
| 64 | + matrix: |
| 65 | + include: |
| 66 | + - target: aarch64-unknown-linux-gnu |
| 67 | + runner: ubuntu-latest |
| 68 | + - target: x86_64-unknown-linux-gnu |
| 69 | + runner: ubuntu-latest |
| 70 | + - target: aarch64-apple-darwin |
| 71 | + runner: macos-14 |
| 72 | + - target: x86_64-apple-darwin |
| 73 | + runner: macos-13 |
| 74 | + - target: x86_64-pc-windows-msvc |
| 75 | + runner: windows-latest |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Show published packages |
| 79 | + run: | |
| 80 | + echo '${{ needs.release.outputs.publishedPackages }}' |
| 81 | +
|
| 82 | + - name: Checkout |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Install system deps (aarch64-unknown-linux-gnu) |
| 86 | + if: ${{matrix.target == 'aarch64-unknown-linux-gnu'}} |
| 87 | + run: | |
| 88 | + sudo apt-get update |
| 89 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross |
| 90 | +
|
| 91 | + - name: Install Rust toolchain |
| 92 | + uses: dtolnay/rust-toolchain@stable |
| 93 | + with: |
| 94 | + components: llvm-tools-preview |
| 95 | + toolchain: 1.88.0 |
| 96 | + target: ${{matrix.target}} |
| 97 | + |
| 98 | + - name: Install pnpm |
| 99 | + run: | |
| 100 | + corepack enable |
| 101 | + corepack prepare pnpm@latest --activate |
| 102 | +
|
| 103 | + - name: Install Node.js |
| 104 | + uses: actions/setup-node@v4 |
| 105 | + with: |
| 106 | + node-version: 22 |
| 107 | + cache: pnpm |
| 108 | + |
| 109 | + - name: Cache Rust dependencies |
| 110 | + uses: Swatinem/rust-cache@v2 |
| 111 | + with: |
| 112 | + shared-key: ${{matrix.target}} |
| 113 | + |
| 114 | + - name: Install Node.js dependencies |
| 115 | + env: |
| 116 | + SKIP_RUST_BUILD: 1 |
| 117 | + run: pnpm install |
| 118 | + |
| 119 | + - name: Build library for aarch64-unknown-linux-gnu |
| 120 | + if: ${{matrix.target == 'aarch64-unknown-linux-gnu'}} |
| 121 | + env: |
| 122 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 123 | + CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc |
| 124 | + CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++ |
| 125 | + run: | |
| 126 | + mkdir -p generated/${{matrix.target}} |
| 127 | + pnpm run build:rust --target=${{matrix.target}} |
| 128 | +
|
| 129 | + - name: Build library |
| 130 | + id: build-library |
| 131 | + if: ${{!contains(fromJSON('["aarch64-unknown-linux-gnu"]'), matrix.target)}} |
| 132 | + run: | |
| 133 | + mkdir -p generated/${{matrix.target}} |
| 134 | + pnpm run build:rust --target=${{matrix.target}} |
| 135 | +
|
| 136 | + - name: Package artifact |
| 137 | + id: package-artifact |
| 138 | + # This needs to be set so that this works on a Windows runner |
| 139 | + shell: bash |
| 140 | + env: |
| 141 | + ARCHIVE_FILENAME: c2pa-node_${{matrix.target}}-v${{ env.PUBLISHED_VERSION || '-dev' }}.zip |
| 142 | + run: | |
| 143 | + cd generated |
| 144 | + 7z a -tzip "${{ env.ARCHIVE_FILENAME }}" c2pa.node |
| 145 | + echo "archive=${{ env.ARCHIVE_FILENAME }}" >> "$GITHUB_OUTPUT" |
| 146 | +
|
| 147 | + - name: Upload artifact (development only) |
| 148 | + id: upload-artifact |
| 149 | + uses: actions/upload-artifact@v4 |
| 150 | + if: needs.release.outputs.published != 'true' |
| 151 | + with: |
| 152 | + name: ${{ steps.package-artifact.outputs.archive }} |
| 153 | + path: generated/${{ steps.package-artifact.outputs.archive }} |
| 154 | + retention-days: 3 |
| 155 | + |
| 156 | + - id: get-release-id |
| 157 | + shell: bash |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + run: | |
| 161 | + echo "id=$(curl -s -L \ |
| 162 | + -H 'Accept: application/vnd.github+json' \ |
| 163 | + -H 'Authorization: Bearer ${{ env.GITHUB_TOKEN }}' \ |
| 164 | + -H 'X-GitHub-Api-Version: 2022-11-28' \ |
| 165 | + https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ env.PUBLISHED_VERSION }} | jq '.id')" >> "$GITHUB_OUTPUT" |
| 166 | +
|
| 167 | + - name: Upload release asset |
| 168 | + if: needs.release.outputs.published == 'true' |
| 169 | + shell: bash |
| 170 | + env: |
| 171 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 172 | + run: | |
| 173 | + curl -L \ |
| 174 | + -X POST \ |
| 175 | + -H "Accept: application/vnd.github+json" \ |
| 176 | + -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ |
| 177 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 178 | + -H "Content-Type: application/zip" \ |
| 179 | + "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.get-release-id.outputs.id }}/assets?name=${{ steps.package-artifact.outputs.archive }}" \ |
| 180 | + --data-binary "@generated/${{ steps.package-artifact.outputs.archive }}" |
0 commit comments