|
| 1 | +name: Try Out Earlier Runners |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "early-runners" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +env: |
| 12 | + # Need these guys for cross-compilation |
| 13 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 14 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc |
| 15 | + |
| 16 | +jobs: |
| 17 | + # windows does not run git cliff so we need to do it here |
| 18 | + extract_version: |
| 19 | + name: Extract Version |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + version: ${{ steps.set_version.outputs.version }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Set up git-cliff |
| 30 | + uses: kenji-miyake/setup-git-cliff@v1 |
| 31 | + |
| 32 | + - name: Set version name |
| 33 | + id: set_version |
| 34 | + run: echo "version=$(git cliff --bumped-version)" >> "$GITHUB_OUTPUT" |
| 35 | + |
| 36 | + build_and_test: |
| 37 | + name: Build & Test for ${{ matrix.config.target }} |
| 38 | + needs: extract_version |
| 39 | + strategy: |
| 40 | + matrix: |
| 41 | + config: |
| 42 | + - { os: ubuntu-20.04, target: x86_64-unknown-linux-gnu } |
| 43 | + - { os: ubuntu-20.04, target: aarch64-unknown-linux-gnu } |
| 44 | + - { os: macos-14, target: x86_64-apple-darwin } |
| 45 | + - { os: macos-14, target: aarch64-apple-darwin } |
| 46 | + - { os: windows-2022, target: x86_64-pc-windows-msvc } |
| 47 | + - { os: windows-2022, target: aarch64-pc-windows-msvc } |
| 48 | + |
| 49 | + runs-on: ${{ matrix.config.os }} |
| 50 | + |
| 51 | + outputs: |
| 52 | + artifact_url: ${{ steps.upload-artifacts.outputs.artifact-url }} |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + with: |
| 57 | + submodules: true |
| 58 | + - uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 59 | + with: |
| 60 | + target: ${{ matrix.config.target }} |
| 61 | + |
| 62 | + - uses: Swatinem/rust-cache@v2 |
| 63 | + id: rust-cache |
| 64 | + |
| 65 | + # The Aarch64 Linux is a special snowflake, we need to install its toolchain |
| 66 | + - name: Install arm64 toolchain |
| 67 | + if: matrix.config.target == 'aarch64-unknown-linux-gnu' |
| 68 | + run: | |
| 69 | + sudo apt-get update |
| 70 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 71 | +
|
| 72 | + # running containers via `services` only works on linux |
| 73 | + # https://github.com/actions/runner/issues/1866 |
| 74 | + - name: 🐘 Setup postgres |
| 75 | + uses: ikalnytskyi/action-setup-postgres@v7 |
| 76 | + |
| 77 | + - name: 🧪 Run Tests |
| 78 | + run: cargo test --release |
| 79 | + env: |
| 80 | + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres |
| 81 | + |
| 82 | + - name: 🛠️ Run Build |
| 83 | + run: cargo build -p pgt_cli --release --target ${{ matrix.config.target }} |
| 84 | + env: |
| 85 | + # Strip all debug symbols from the resulting binaries |
| 86 | + RUSTFLAGS: "-C strip=symbols -C codegen-units=1" |
| 87 | + # Inline the version in the CLI binary |
| 88 | + PGT_VERSION: ${{ needs.extract_version.outputs.version }} |
| 89 | + |
| 90 | + # windows is a special snowflake too, it saves binaries as .exe |
| 91 | + - name: 👦 Name the Binary |
| 92 | + if: matrix.config.os == 'windows-latest' |
| 93 | + run: | |
| 94 | + mkdir dist |
| 95 | + cp target/${{ matrix.config.target }}/release/postgrestools.exe ./dist/postgrestools_${{ matrix.config.target }} |
| 96 | + - name: 👦 Name the Binary |
| 97 | + if: matrix.config.os != 'windows-latest' |
| 98 | + run: | |
| 99 | + mkdir dist |
| 100 | + cp target/${{ matrix.config.target }}/release/postgrestools ./dist/postgrestools_${{ matrix.config.target }} |
| 101 | +
|
| 102 | + # It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other. |
| 103 | + # A common workaround is to upload and download the resulting artifacts. |
| 104 | + - name: 👆 Upload Artifacts |
| 105 | + id: upload-artifacts |
| 106 | + uses: actions/upload-artifact@v4 |
| 107 | + with: |
| 108 | + name: postgrestools_${{ matrix.config.target }} |
| 109 | + path: ./dist/postgrestools_* |
| 110 | + # The default compression level is 6; this took the binary down from 350 to 330MB. |
| 111 | + # It is recommended to use a lower level for binaries, since the compressed result is not much smaller, |
| 112 | + # and the higher levels of compression take much longer. |
| 113 | + compression-level: 2 |
| 114 | + if-no-files-found: error |
| 115 | + |
| 116 | + add-pr-comment: |
| 117 | + runs-on: ubuntu-latest |
| 118 | + needs: build_and_test # make sure that tests & build work correctly |
| 119 | + steps: |
| 120 | + - name: Checkout Repo |
| 121 | + uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + # we need all commits to create a changelog |
| 124 | + fetch-depth: 0 |
| 125 | + |
| 126 | + - name: Make Artifacts Dir |
| 127 | + run: mkdir artifacts |
| 128 | + |
| 129 | + - name: 👇 Download Artifacts |
| 130 | + uses: actions/download-artifact@v4 |
| 131 | + id: download |
| 132 | + with: |
| 133 | + merge-multiple: true |
| 134 | + path: artifacts |
| 135 | + pattern: postgrestools_* |
| 136 | + |
| 137 | + - name: Zip 'Em Up |
| 138 | + run: zip -r artifacts.zip artifacts |
| 139 | + |
| 140 | + - name: Add PR Comment |
| 141 | + uses: thollander/actions-comment-pull-request@v3 |
| 142 | + with: |
| 143 | + file-path: artifacts.zip |
0 commit comments