|
| 1 | +name: Release PG_CLI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + |
| 9 | +env: |
| 10 | + # Ultimately, we shouldn't ignore warnings. |
| 11 | + # We need to pass it as an ENV because inlining doesn't work on Windows. |
| 12 | + RUSTFLAGS: -A dead_code |
| 13 | + # Need these guys for cross-compilation |
| 14 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 15 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc |
| 16 | + |
| 17 | +jobs: |
| 18 | + build_and_test: |
| 19 | + name: Build & Test for ${{ matrix.config.target }} |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + config: |
| 23 | + - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu } |
| 24 | + - { os: ubuntu-latest, target: aarch64-unknown-linux-gnu } |
| 25 | + - { os: macos-latest, target: x86_64-apple-darwin } |
| 26 | + - { os: macos-latest, target: aarch64-apple-darwin } |
| 27 | + - { os: windows-latest, target: x86_64-pc-windows-msvc } |
| 28 | + - { os: windows-latest, target: aarch64-pc-windows-msvc } |
| 29 | + |
| 30 | + runs-on: ${{ matrix.config.os }} |
| 31 | + |
| 32 | + outputs: |
| 33 | + artifact_url: ${{ steps.upload-artifacts.outputs.artifact-url }} |
| 34 | + |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + submodules: true |
| 39 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 40 | + with: |
| 41 | + target: ${{ matrix.config.target }} |
| 42 | + |
| 43 | + - uses: Swatinem/rust-cache@v2 |
| 44 | + id: rust-cache |
| 45 | + |
| 46 | + # The Aarch64 Linux is a special snowflake, we need to install its toolchain |
| 47 | + - name: Install arm64 toolchain |
| 48 | + if: matrix.config.target == 'aarch64-unknown-linux-gnu' |
| 49 | + run: | |
| 50 | + sudo apt-get update |
| 51 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 52 | +
|
| 53 | + # running containers via `services` only works on linux |
| 54 | + # https://github.com/actions/runner/issues/1866 |
| 55 | + - name: π Setup postgres |
| 56 | + uses: ikalnytskyi/action-setup-postgres@v7 |
| 57 | + |
| 58 | + - name: π§ͺ Run Tests |
| 59 | + run: cargo test --release |
| 60 | + env: |
| 61 | + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres |
| 62 | + |
| 63 | + - name: π οΈ Run Build |
| 64 | + run: cargo build -p pg_cli --release --target ${{ matrix.config.target }} |
| 65 | + |
| 66 | + # windows is a special snowflake to, it saves binaries as .exe |
| 67 | + - name: π¦ Name the Binary |
| 68 | + if: matrix.config.os == 'windows-latest' |
| 69 | + run: | |
| 70 | + mkdir dist |
| 71 | + cp target/${{ matrix.config.target }}/release/pg_cli.exe ./dist/pgcli_${{ matrix.config.target }} |
| 72 | + - name: π¦ Name the Binary |
| 73 | + if: matrix.config.os != 'windows-latest' |
| 74 | + run: | |
| 75 | + mkdir dist |
| 76 | + cp target/${{ matrix.config.target }}/release/pg_cli ./dist/pgcli_${{ matrix.config.target }} |
| 77 | +
|
| 78 | + # It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other. |
| 79 | + # A common workaround is to upload and download the resulting artifacts. |
| 80 | + - name: π Upload Artifacts |
| 81 | + id: upload-artifacts |
| 82 | + uses: actions/upload-artifact@v4 |
| 83 | + with: |
| 84 | + name: pgcli_${{ matrix.config.target }} |
| 85 | + path: ./dist/pgcli_* |
| 86 | + # The default compression level is 6; this took the binary down from 350 to 330MB. |
| 87 | + # It is recommended to use a lower level for binaries, since the compressed result is not much smaller, |
| 88 | + # and the higher levels of compression take much longer. |
| 89 | + compression-level: 2 |
| 90 | + if-no-files-found: error |
| 91 | + |
| 92 | + create_changelog_and_release: |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: build_and_test # make sure that tests & build work correctly |
| 95 | + steps: |
| 96 | + - name: Checkout Repo |
| 97 | + uses: actions/checkout@v4 |
| 98 | + with: |
| 99 | + # we need all commits to create a changelog |
| 100 | + fetch-depth: 0 |
| 101 | + |
| 102 | + - name: π Create Changelog |
| 103 | + uses: orhun/git-cliff-action@v3 |
| 104 | + id: create_changelog |
| 105 | + with: |
| 106 | + config: cliff.toml |
| 107 | + args: --bump --latest |
| 108 | + env: |
| 109 | + GITHUB_REPO: ${{ github.repository }} |
| 110 | + |
| 111 | + - name: π Download Artifacts |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + id: download |
| 114 | + with: |
| 115 | + merge-multiple: true |
| 116 | + pattern: pgcli_* |
| 117 | + |
| 118 | + - name: π Create Release |
| 119 | + uses: softprops/action-gh-release@v2 |
| 120 | + id: create-release |
| 121 | + env: |
| 122 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + with: |
| 124 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + body: ${{ steps.create_changelog.outputs.content }} |
| 126 | + tag_name: ${{ steps.create_changelog.outputs.version }} |
| 127 | + files: pgcli_* |
| 128 | + fail_on_unmatched_files: true |
| 129 | + draft: true |
| 130 | + |
| 131 | + - name: β
Output Link to Worflow Summary |
| 132 | + run: | |
| 133 | + { |
| 134 | + echo "# π Release completed!" |
| 135 | + echo "" |
| 136 | + echo "Here is the URL to the Release Draft:" |
| 137 | + echo "" |
| 138 | + echo "[Link](${{ steps.create-release.outputs.url }})" |
| 139 | + echo "" |
| 140 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments