|
| 1 | +# Taken from ripgrep with modifications |
| 2 | +# Taken from mitsuhiko/rye with modifications |
| 3 | +# |
| 4 | +# Reference: |
| 5 | +# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/ |
| 6 | + |
| 7 | +name: release |
| 8 | +on: |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 12 | + |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + version: |
| 16 | + type: string |
| 17 | + description: "Release version" |
| 18 | + required: true |
| 19 | + dry-run: |
| 20 | + type: choice |
| 21 | + description: "Dry Run" |
| 22 | + options: |
| 23 | + - "no" |
| 24 | + - "yes" |
| 25 | + required: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + create-release: |
| 29 | + name: create-release |
| 30 | + runs-on: ubuntu-22.04 |
| 31 | + |
| 32 | + outputs: |
| 33 | + pyql_version: ${{ env.PYQL_VERSION }} |
| 34 | + pyql_dry_run: ${{ env.PYQL_DRY_RUN }} |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Inputs from workflow dispatch |
| 38 | + shell: bash |
| 39 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 40 | + run: | |
| 41 | + echo "PYQL_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV |
| 42 | + echo "PYQL_DRY_RUN=${{ github.event.inputs.dry-run }}" >> $GITHUB_ENV |
| 43 | + echo "PYQL_VERSION: ${{ github.event.inputs.version }}" |
| 44 | + echo "PYQL_DRY_RUN: ${{ github.event.inputs.dry-run }}" |
| 45 | +
|
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Get the release version from the tag |
| 50 | + shell: bash |
| 51 | + if: env.PYQL_VERSION == '' |
| 52 | + run: | |
| 53 | + # Apparently, this is the right way to get a tag name. Really? |
| 54 | + # |
| 55 | + # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 |
| 56 | + echo "PYQL_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| 57 | + echo "version is: ${{ env.PYQL_VERSION }}" |
| 58 | +
|
| 59 | + - name: Create GitHub release |
| 60 | + id: release |
| 61 | + if: env.PYQL_DRY_RUN != 'yes' |
| 62 | + env: |
| 63 | + GH_TOKEN: ${{ secrets.TOKEN }} |
| 64 | + run: gh release create --draft --title "${{ env.PYQL_VERSION }}" "${{ env.PYQL_VERSION }}" |
| 65 | + |
| 66 | + build-release: |
| 67 | + name: build-release |
| 68 | + needs: ["create-release"] |
| 69 | + runs-on: ${{ matrix.os }} |
| 70 | + env: |
| 71 | + # For some builds, we use cross to test on 32-bit and big-endian |
| 72 | + # systems. |
| 73 | + CARGO: cargo |
| 74 | + # When CARGO is set to CROSS, this is set to `--target matrix.target`. |
| 75 | + TARGET_FLAGS: "" |
| 76 | + # When CARGO is set to CROSS, TARGET_DIR includes matrix.target. |
| 77 | + TARGET_DIR: ./target |
| 78 | + # Emit backtraces on panics. |
| 79 | + RUST_BACKTRACE: 1 |
| 80 | + strategy: |
| 81 | + matrix: |
| 82 | + build: [linux, macos, macos-arm, win-msvc, win32-msvc] |
| 83 | + include: |
| 84 | + - build: linux |
| 85 | + os: ubuntu-22.04 |
| 86 | + rust: stable |
| 87 | + target: x86_64-unknown-linux-musl |
| 88 | + name: x86_64-linux |
| 89 | + - build: linux-arm |
| 90 | + os: ubuntu-22.04 |
| 91 | + rust: stable |
| 92 | + target: aarch64-unknown-linux-musl |
| 93 | + name: aarch64-linux |
| 94 | + - build: macos |
| 95 | + os: macos-12 |
| 96 | + rust: stable |
| 97 | + target: x86_64-apple-darwin |
| 98 | + name: x86_64-macos |
| 99 | + - build: macos-arm |
| 100 | + os: macos-12 |
| 101 | + rust: stable |
| 102 | + target: aarch64-apple-darwin |
| 103 | + name: aarch64-macos |
| 104 | + - build: win-msvc |
| 105 | + os: windows-2022 |
| 106 | + rust: stable |
| 107 | + target: x86_64-pc-windows-msvc |
| 108 | + name: x86_64-windows |
| 109 | + - build: win32-msvc |
| 110 | + os: windows-2022 |
| 111 | + rust: stable |
| 112 | + target: i686-pc-windows-msvc |
| 113 | + name: x86-windows |
| 114 | + |
| 115 | + steps: |
| 116 | + - name: Checkout repository |
| 117 | + uses: actions/checkout@v3 |
| 118 | + |
| 119 | + - name: Install Rust |
| 120 | + uses: dtolnay/rust-toolchain@master |
| 121 | + with: |
| 122 | + toolchain: ${{ matrix.rust }} |
| 123 | + target: ${{ matrix.target }} |
| 124 | + |
| 125 | + - name: Use Cross |
| 126 | + shell: bash |
| 127 | + run: | |
| 128 | + cargo install cross |
| 129 | + echo "CARGO=cross" >> $GITHUB_ENV |
| 130 | + echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV |
| 131 | + echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV |
| 132 | +
|
| 133 | + - name: Show command used for Cargo |
| 134 | + run: | |
| 135 | + echo "cargo command is: ${{ env.CARGO }}" |
| 136 | + echo "target flag is: ${{ env.TARGET_FLAGS }}" |
| 137 | + echo "target dir is: ${{ env.TARGET_DIR }}" |
| 138 | +
|
| 139 | + - name: Build release binary |
| 140 | + run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} |
| 141 | + |
| 142 | + - name: Build release file |
| 143 | + shell: bash |
| 144 | + run: | |
| 145 | + chmod +x scripts/cargo-out-dir |
| 146 | + outdir="$(scripts/cargo-out-dir "${{ env.TARGET_DIR }}")" |
| 147 | + bin="pyql-${{ matrix.name }}" |
| 148 | +
|
| 149 | + if [ "${{ matrix.os }}" = "windows-2022" ]; then |
| 150 | + cp "target/${{ matrix.target }}/release/pyql.exe" "$bin.exe" |
| 151 | + python scripts/sha256.py $bin.exe > "$bin.exe.sha256" |
| 152 | + echo "ASSET=$bin.exe" >> $GITHUB_ENV |
| 153 | + echo "SHA256_FILE=$bin.exe.sha256" >> $GITHUB_ENV |
| 154 | + else |
| 155 | + cp "target/${{ matrix.target }}/release/pyql" "$bin" |
| 156 | + gzip "$bin" |
| 157 | + python scripts/sha256.py $bin.gz > "$bin.gz.sha256" |
| 158 | + echo "ASSET=$bin.gz" >> $GITHUB_ENV |
| 159 | + echo "SHA256_FILE=$bin.gz.sha256" >> $GITHUB_ENV |
| 160 | + fi |
| 161 | +
|
| 162 | + - name: Upload release archive |
| 163 | + if: ${{ needs.create-release.outputs.pyql_dry_run }} != 'yes' |
| 164 | + env: |
| 165 | + GH_TOKEN: ${{ secrets.TOKEN }} |
| 166 | + run: | |
| 167 | + gh release upload "${{ needs.create-release.outputs.pyql_version }}" "${{ env.ASSET }}" |
| 168 | + gh release upload "${{ needs.create-release.outputs.pyql_version }}" "${{ env.SHA256_FILE }}" |
| 169 | +
|
| 170 | + - name: Upload artifact |
| 171 | + uses: actions/upload-artifact@v4 |
| 172 | + with: |
| 173 | + name: ${{ env.ASSET }} |
| 174 | + path: ${{ env.ASSET }} |
| 175 | + |
| 176 | + - name: Upload artifact hash |
| 177 | + uses: actions/upload-artifact@v4 |
| 178 | + with: |
| 179 | + name: ${{ env.SHA256_FILE }} |
| 180 | + path: ${{ env.SHA256_FILE }} |
| 181 | + |
| 182 | + write-release-meta: |
| 183 | + name: write-release-meta |
| 184 | + runs-on: ubuntu-22.04 |
| 185 | + needs: ["create-release", "build-release"] |
| 186 | + |
| 187 | + steps: |
| 188 | + - name: Checkout repository |
| 189 | + uses: actions/checkout@v3 |
| 190 | + |
| 191 | + - name: Upload Release Meta |
| 192 | + if: ${{ needs.create-release.outputs.pyql_dry_run }} != 'yes' |
| 193 | + shell: bash |
| 194 | + env: |
| 195 | + GH_TOKEN: ${{ secrets.TOKEN }} |
| 196 | + run: | |
| 197 | + gh run download $GH_RUNID -D artifacts-tmp -p "*.sha256" |
| 198 | + python scripts/summarize-release.py "${{ needs.create-release.outputs.pyql_version }}" artifacts-tmp > MANIFEST.json |
| 199 | + gh release upload "${{ needs.create-release.outputs.pyql_version }}" MANIFEST.json |
| 200 | +
|
| 201 | + - name: Upload artifact hash |
| 202 | + uses: actions/upload-artifact@v4 |
| 203 | + with: |
| 204 | + name: MANIFEST.json |
| 205 | + path: MANIFEST.json |
0 commit comments