|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + schedule: |
| 8 | + # 00:00 UTC+8 -> 16:00 |
| 9 | + - cron: "0 16 * * *" |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + type: string |
| 14 | + description: The version to be released. |
| 15 | + required: true |
| 16 | + ref: |
| 17 | + type: string |
| 18 | + description: | |
| 19 | + Ref to checkout. |
| 20 | + For tags, use the prefix "refs/tags/". |
| 21 | + For branchs, use the prefix "refs/heads/". |
| 22 | + required: true |
| 23 | + default: refs/heads/main |
| 24 | + prerelease: |
| 25 | + type: boolean |
| 26 | + description: Prerelease or not. |
| 27 | + required: true |
| 28 | + default: true |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: write |
| 32 | + pull-requests: read |
| 33 | + |
| 34 | +env: |
| 35 | + CARGO_TERM_COLOR: always |
| 36 | + |
| 37 | +jobs: |
| 38 | + setup: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v3 |
| 43 | + - name: Check recents |
| 44 | + id: check-recents |
| 45 | + run: | |
| 46 | + commit_date=$(git log -1 --since="24 hours ago" --pretty=format:"%cI") |
| 47 | + if [[ -n "$commit_date" ]]; |
| 48 | + then echo "recents=true" >> $GITHUB_OUTPUT; |
| 49 | + else echo "recents=false" >> $GITHUB_OUTPUT; |
| 50 | + fi |
| 51 | + shell: bash |
| 52 | + - name: Set version, recheck, ref, prerelease |
| 53 | + id: sets |
| 54 | + uses: actions/github-script@v6 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + if ("${{ github.event_name }}" == 'push') { |
| 58 | + if (context.ref.startsWith("refs/tags/")) { |
| 59 | + let version = context.ref.substring("refs/tags/".length); |
| 60 | + core.setOutput('version', version); |
| 61 | + core.setOutput('recheck', 'true'); |
| 62 | + core.setOutput('ref', context.ref); |
| 63 | + core.setOutput('prerelease', false); |
| 64 | + } else { |
| 65 | + throw new Error("unreachable"); |
| 66 | + } |
| 67 | + } else if ("${{ github.event_name }}" == 'schedule') { |
| 68 | + let date = new Date(); |
| 69 | + date.setHours(date.getHours() + 8); |
| 70 | + var yyyy = date.getUTCFullYear(); |
| 71 | + var mm = String(1 + date.getUTCMonth()).padStart(2, '0'); |
| 72 | + var dd = String(0 + date.getUTCDate()).padStart(2, '0'); |
| 73 | + let version = `v0.0.0-nightly.${yyyy}${mm}${dd}`; |
| 74 | + core.setOutput('version', version); |
| 75 | + if ("${{ steps.check-recents.outputs.recents }}" == "true") { |
| 76 | + core.setOutput('recheck', 'true'); |
| 77 | + } else { |
| 78 | + core.setOutput('recheck', 'false'); |
| 79 | + } |
| 80 | + core.setOutput('ref', 'refs/heads/main'); |
| 81 | + core.setOutput('prerelease', true); |
| 82 | + } else if ("${{ github.event_name }}" == 'workflow_dispatch') { |
| 83 | + let version = "${{ github.event.inputs.version }}"; |
| 84 | + let ref = "${{ github.event.inputs.ref }}"; |
| 85 | + let prerelease = "${{ github.event.inputs.prerelease }}"; |
| 86 | + core.setOutput('version', version); |
| 87 | + core.setOutput('recheck', 'true'); |
| 88 | + core.setOutput('ref', ref); |
| 89 | + core.setOutput('prerelease', prerelease); |
| 90 | + } else { |
| 91 | + throw new Error("unreachable"); |
| 92 | + } |
| 93 | + outputs: |
| 94 | + version: ${{ steps.sets.outputs.version }} |
| 95 | + recheck: ${{ steps.sets.outputs.recheck }} |
| 96 | + ref: ${{ steps.sets.outputs.ref }} |
| 97 | + prerelease: ${{ steps.sets.outputs.prerelease }} |
| 98 | + release: |
| 99 | + strategy: |
| 100 | + matrix: |
| 101 | + version: [15] |
| 102 | + needs: setup |
| 103 | + runs-on: ubuntu-latest |
| 104 | + if: ${{ needs.setup.outputs.recheck == 'true' }} |
| 105 | + steps: |
| 106 | + - name: Checkout |
| 107 | + uses: actions/checkout@v3 |
| 108 | + with: |
| 109 | + ref: ${{ needs.setup.outputs.ref }} |
| 110 | + - name: Prepare |
| 111 | + run: | |
| 112 | + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' |
| 113 | + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - |
| 114 | + sudo apt-get update |
| 115 | + sudo apt-get -y install libpq-dev postgresql-${{ matrix.version }} postgresql-server-dev-${{ matrix.version }} |
| 116 | + cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) |
| 117 | + cargo pgrx init --pg${{ matrix.version }}=/usr/lib/postgresql/${{ matrix.version }}/bin/pg_config |
| 118 | + - name: Build Release |
| 119 | + id: build_release |
| 120 | + run: | |
| 121 | + sudo apt-get install ruby-dev libarchive-tools |
| 122 | + sudo gem install --no-document fpm |
| 123 | + cargo pgrx package |
| 124 | + mkdir ./artifacts |
| 125 | + mv ./target/release/vectors-pg${{ matrix.version }}/usr ./artifacts/usr |
| 126 | + fpm \ |
| 127 | + --input-type dir \ |
| 128 | + --output-type deb \ |
| 129 | + --name vectors-pg${{ matrix.version }} \ |
| 130 | + --version ${{ needs.setup.outputs.version }} \ |
| 131 | + --license apache2 \ |
| 132 | + --deb-no-default-config-files \ |
| 133 | + --package ./vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-amd64-unknown-linux-gnu.deb \ |
| 134 | + --architecture amd64 \ |
| 135 | + ./artifacts |
| 136 | + fpm \ |
| 137 | + --input-type dir \ |
| 138 | + --output-type rpm \ |
| 139 | + --name vectors-pg${{ matrix.version }} \ |
| 140 | + --version ${{ needs.setup.outputs.version }} \ |
| 141 | + --license apache2 \ |
| 142 | + --deb-no-default-config-files \ |
| 143 | + --package ./vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-x86_64-unknown-linux-gnu.rpm \ |
| 144 | + --architecture x86_64 \ |
| 145 | + ./artifacts |
| 146 | + fpm \ |
| 147 | + --input-type dir \ |
| 148 | + --output-type pacman \ |
| 149 | + --name vectors-pg${{ matrix.version }} \ |
| 150 | + --version ${{ needs.setup.outputs.version }} \ |
| 151 | + --license apache2 \ |
| 152 | + --deb-no-default-config-files \ |
| 153 | + --package ./vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-x86_64-unknown-linux-gnu.tar.zst \ |
| 154 | + --architecture x86_64 \ |
| 155 | + ./artifacts |
| 156 | + - name: Create Release |
| 157 | + id: create_release |
| 158 | + uses: actions/create-release@v1 |
| 159 | + env: |
| 160 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 161 | + with: |
| 162 | + tag_name: ${{ needs.setup.outputs.version }} |
| 163 | + release_name: ${{ needs.setup.outputs.version }} |
| 164 | + draft: false |
| 165 | + prerelease: ${{ needs.setup.outputs.prerelease }} |
| 166 | + - name: Upload Release / DEB |
| 167 | + id: upload_release_deb |
| 168 | + uses: actions/upload-release-asset@v1 |
| 169 | + env: |
| 170 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 171 | + with: |
| 172 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 173 | + asset_path: ./vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-amd64-unknown-linux-gnu.deb |
| 174 | + asset_name: vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-amd64-unknown-linux-gnu.deb |
| 175 | + asset_content_type: application/vnd.debian.binary-package |
| 176 | + - name: Upload Release / RPM |
| 177 | + id: upload_release_rpm |
| 178 | + uses: actions/upload-release-asset@v1 |
| 179 | + env: |
| 180 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 181 | + with: |
| 182 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 183 | + asset_path: ./vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-x86_64-unknown-linux-gnu.rpm |
| 184 | + asset_name: vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-x86_64-unknown-linux-gnu.rpm |
| 185 | + asset_content_type: application/x-rpm |
| 186 | + - name: Upload Release / PACMAN |
| 187 | + id: upload_release_pacman |
| 188 | + uses: actions/upload-release-asset@v1 |
| 189 | + env: |
| 190 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 191 | + with: |
| 192 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 193 | + asset_path: ./vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-x86_64-unknown-linux-gnu.tar.zst |
| 194 | + asset_name: vectors-pg${{ matrix.version }}-${{ needs.setup.outputs.version }}-x86_64-unknown-linux-gnu.tar.zst |
| 195 | + asset_content_type: application/octet-stream |
0 commit comments