|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: release-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +jobs: |
| 13 | + release-please: |
| 14 | + if: ${{ github.repository == 'Gitlawb/node' }} |
| 15 | + name: Release Please |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: write |
| 19 | + pull-requests: write |
| 20 | + outputs: |
| 21 | + release_created: ${{ steps.release.outputs.release_created }} |
| 22 | + tag_name: ${{ steps.release.outputs.tag_name }} |
| 23 | + version: ${{ steps.release.outputs.version }} |
| 24 | + steps: |
| 25 | + - name: Run release-please |
| 26 | + id: release |
| 27 | + uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.3.0 |
| 28 | + with: |
| 29 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + docker: |
| 32 | + name: Build & Push Docker Image |
| 33 | + needs: release-please |
| 34 | + if: ${{ needs.release-please.outputs.release_created == 'true' }} |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + packages: write |
| 39 | + steps: |
| 40 | + - name: Checkout release tag |
| 41 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 42 | + with: |
| 43 | + ref: ${{ needs.release-please.outputs.tag_name }} |
| 44 | + |
| 45 | + - name: Set up QEMU |
| 46 | + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 |
| 47 | + |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 |
| 50 | + |
| 51 | + - name: Log in to GitHub Container Registry |
| 52 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 53 | + with: |
| 54 | + registry: ghcr.io |
| 55 | + username: ${{ github.actor }} |
| 56 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Extract metadata |
| 59 | + id: meta |
| 60 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 61 | + with: |
| 62 | + images: ghcr.io/${{ github.repository }} |
| 63 | + tags: | |
| 64 | + type=semver,pattern={{version}},value=${{ needs.release-please.outputs.version }} |
| 65 | + type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-please.outputs.version }} |
| 66 | + type=raw,value=latest |
| 67 | +
|
| 68 | + - name: Build and load locally (smoke) |
| 69 | + uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0 |
| 70 | + with: |
| 71 | + context: . |
| 72 | + load: true |
| 73 | + tags: gitlawb-node:smoke |
| 74 | + cache-from: type=gha |
| 75 | + |
| 76 | + - name: Smoke test |
| 77 | + run: docker run --rm gitlawb-node:smoke --version |
| 78 | + |
| 79 | + - name: Build and push (multi-arch) |
| 80 | + uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0 |
| 81 | + with: |
| 82 | + context: . |
| 83 | + platforms: linux/amd64,linux/arm64 |
| 84 | + push: true |
| 85 | + tags: ${{ steps.meta.outputs.tags }} |
| 86 | + labels: ${{ steps.meta.outputs.labels }} |
| 87 | + cache-from: type=gha |
| 88 | + cache-to: type=gha,mode=max |
| 89 | + |
| 90 | + - name: Release summary |
| 91 | + run: | |
| 92 | + { |
| 93 | + echo "## Released ${{ needs.release-please.outputs.tag_name }}" |
| 94 | + echo |
| 95 | + echo "- Image: \`ghcr.io/${{ github.repository }}:${{ needs.release-please.outputs.version }}\`" |
| 96 | + echo "- GitHub: https://github.com/${{ github.repository }}/releases/tag/${{ needs.release-please.outputs.tag_name }}" |
| 97 | + } >> "$GITHUB_STEP_SUMMARY" |
| 98 | +
|
| 99 | + release-binaries: |
| 100 | + name: Build & Attach Binaries |
| 101 | + needs: release-please |
| 102 | + if: ${{ needs.release-please.outputs.release_created == 'true' }} |
| 103 | + runs-on: ${{ matrix.os }} |
| 104 | + permissions: |
| 105 | + contents: write |
| 106 | + strategy: |
| 107 | + fail-fast: false |
| 108 | + matrix: |
| 109 | + include: |
| 110 | + - target: x86_64-unknown-linux-musl |
| 111 | + os: ubuntu-latest |
| 112 | + - target: aarch64-unknown-linux-musl |
| 113 | + os: ubuntu-latest |
| 114 | + - target: x86_64-apple-darwin |
| 115 | + os: macos-13 |
| 116 | + - target: aarch64-apple-darwin |
| 117 | + os: macos-14 |
| 118 | + steps: |
| 119 | + - name: Checkout release tag |
| 120 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 121 | + with: |
| 122 | + ref: ${{ needs.release-please.outputs.tag_name }} |
| 123 | + |
| 124 | + - name: Set up Rust toolchain |
| 125 | + uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # stable |
| 126 | + with: |
| 127 | + toolchain: stable |
| 128 | + targets: ${{ matrix.target }} |
| 129 | + |
| 130 | + - name: Install musl tools (linux) |
| 131 | + if: contains(matrix.target, 'linux-musl') |
| 132 | + run: | |
| 133 | + sudo apt-get update |
| 134 | + sudo apt-get install -y musl-tools |
| 135 | + if [ "${{ matrix.target }}" = "aarch64-unknown-linux-musl" ]; then |
| 136 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 137 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" |
| 138 | + echo "CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV" |
| 139 | + fi |
| 140 | +
|
| 141 | + - name: Cache cargo |
| 142 | + uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 |
| 143 | + with: |
| 144 | + key: ${{ matrix.target }} |
| 145 | + |
| 146 | + - name: Build |
| 147 | + run: cargo build --release --target ${{ matrix.target }} -p gl -p git-remote-gitlawb -p gitlawb-node |
| 148 | + |
| 149 | + - name: Package |
| 150 | + id: pkg |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + set -euo pipefail |
| 154 | + NAME="gitlawb-node-${{ needs.release-please.outputs.version }}-${{ matrix.target }}" |
| 155 | + mkdir -p "dist/$NAME" |
| 156 | + cp "target/${{ matrix.target }}/release/gl" "dist/$NAME/" |
| 157 | + cp "target/${{ matrix.target }}/release/git-remote-gitlawb" "dist/$NAME/" |
| 158 | + cp "target/${{ matrix.target }}/release/gitlawb-node" "dist/$NAME/" |
| 159 | + cp README.md LICENSE-MIT LICENSE-APACHE "dist/$NAME/" |
| 160 | + cd dist |
| 161 | + tar czf "$NAME.tar.gz" "$NAME" |
| 162 | + shasum -a 256 "$NAME.tar.gz" > "$NAME.tar.gz.sha256" |
| 163 | + echo "asset=dist/$NAME.tar.gz" >> "$GITHUB_OUTPUT" |
| 164 | + echo "checksum=dist/$NAME.tar.gz.sha256" >> "$GITHUB_OUTPUT" |
| 165 | +
|
| 166 | + - name: Attach to release |
| 167 | + uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 # v2.3.2 |
| 168 | + with: |
| 169 | + tag_name: ${{ needs.release-please.outputs.tag_name }} |
| 170 | + files: | |
| 171 | + ${{ steps.pkg.outputs.asset }} |
| 172 | + ${{ steps.pkg.outputs.checksum }} |
0 commit comments