|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + type: string |
| 8 | + description: Version |
| 9 | + required: true |
| 10 | + tag: |
| 11 | + type: string |
| 12 | + description: Tag |
| 13 | + required: true |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +env: |
| 20 | + CARGO_TERM_COLOR: always |
| 21 | + RUST_BACKTRACE: 1 |
| 22 | + SCCACHE_GHA_ENABLED: true |
| 23 | + RUSTC_WRAPPER: sccache |
| 24 | + RUSTFLAGS: "-Dwarnings" |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: write |
| 28 | + pull-requests: read |
| 29 | + |
| 30 | +jobs: |
| 31 | + semver: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - uses: actions/github-script@v7 |
| 35 | + with: |
| 36 | + script: | |
| 37 | + const r = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; |
| 38 | + if (!r.test("${{ github.event.inputs.version }}")) { |
| 39 | + core.setFailed(`Action failed with an invalid semver.`); |
| 40 | + } |
| 41 | + binary: |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + version: [12, 13, 14, 15, 16] |
| 45 | + arch: ["x86_64", "aarch64"] |
| 46 | + runs-on: ubuntu-20.04 |
| 47 | + env: |
| 48 | + SEMVER: ${{ github.event.inputs.version }} |
| 49 | + VERSION: ${{ matrix.version }} |
| 50 | + ARCH: ${{ matrix.arch }} |
| 51 | + needs: ["semver"] |
| 52 | + steps: |
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v4 |
| 55 | + - name: Set up Environment |
| 56 | + run: | |
| 57 | + sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' |
| 58 | + sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' |
| 59 | + sudo apt-get update |
| 60 | + sudo apt-get install -y build-essential crossbuild-essential-arm64 |
| 61 | + sudo apt-get install -y qemu-user-static |
| 62 | + echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' | tee ~/.cargo/config.toml |
| 63 | + - name: Set up Sccache |
| 64 | + uses: mozilla-actions/sccache-action@v0.0.4 |
| 65 | + - name: Set up Cache |
| 66 | + uses: actions/cache/restore@v4 |
| 67 | + id: cache |
| 68 | + with: |
| 69 | + path: | |
| 70 | + ~/.cargo/registry/index/ |
| 71 | + ~/.cargo/registry/cache/ |
| 72 | + ~/.cargo/git/db/ |
| 73 | + key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }} |
| 74 | + - name: Set up Clang-16 |
| 75 | + run: | |
| 76 | + sudo sh -c 'echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-16 main" >> /etc/apt/sources.list' |
| 77 | + wget --quiet -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - |
| 78 | + sudo apt-get update |
| 79 | + sudo apt-get install -y clang-16 |
| 80 | + - name: Set up Pgrx |
| 81 | + run: | |
| 82 | + # pg_config |
| 83 | + mkdir -p ~/.pg_config |
| 84 | + touch ~/.pg_config/pg_config |
| 85 | + chmod 777 ~/.pg_config/pg_config |
| 86 | + echo "#!/usr/bin/env bash" >> ~/.pg_config/pg_config |
| 87 | + echo "$(pwd)/tools/pg_config.sh \"\$@\" < $(pwd)/vendor/pg_config/pg${VERSION}_${ARCH}-unknown-linux-gnu.txt" >> ~/.pg_config/pg_config |
| 88 | + mkdir -p ~/.pgrx && echo "configs.pg$VERSION=\"$HOME/.pg_config/pg_config\"" > ~/.pgrx/config.toml |
| 89 | + # pgrx_binding |
| 90 | + mkdir -p ~/.pgrx_binding |
| 91 | + cp ./vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs ~/.pgrx_binding/pg${VERSION}_raw_bindings.rs |
| 92 | + echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV" |
| 93 | + - name: Build |
| 94 | + run: | |
| 95 | + cargo build --lib --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu |
| 96 | + ./tools/schema.sh --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/pg_bestmatch--$SEMVER.sql |
| 97 | + - name: Package |
| 98 | + run: | |
| 99 | + export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/') |
| 100 | + ./scripts/package.sh |
| 101 | + - name: Upload |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ github.token }} |
| 104 | + run: | |
| 105 | + export TAG=${{ github.event.inputs.tag }} |
| 106 | + export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/') |
| 107 | + gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip |
| 108 | + gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${SEMVER}_${PLATFORM}.deb |
| 109 | + - name: Post Set up Cache |
| 110 | + uses: actions/cache/save@v4 |
| 111 | + if: ${{ !steps.cache.outputs.cache-hit }} |
| 112 | + with: |
| 113 | + path: | |
| 114 | + ~/.cargo/registry/index/ |
| 115 | + ~/.cargo/registry/cache/ |
| 116 | + ~/.cargo/git/db/ |
| 117 | + key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }} |
0 commit comments