ci: rebuild release infrastructure on GitHub Actions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Andrew Gallant · committed by Andrew Gallant · parent 1ece506 · Browse files · 1 file·+211 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+211 added−0 removed
- other:+211 added−0 removed
Provenance
- Commit
cda9acb- Tree
a6cd8df- Author
Andrew Gallant <jamslam@gmail.com>- Committer
Andrew Gallant <jamslam@gmail.com>- Parent
1ece506
1 file changed+211 added−0 removed
added:.github/workflows/release.yml+211 added
1+# The way this works is a little weird. But basically, the create-release job2+# runs purely to initialize the GitHub release itself. Once done, the upload3+# URL of the release is saved as an artifact.4+#5+# The build-release job runs only once create-release is finished. It gets6+# the release upload URL by downloading the corresponding artifact (which was7+# uploaded by create-release). It then builds the release executables for each8+# supported platform and attaches them as release assets to the previously9+# created release.10+#11+# The key here is that we create the release only once.12+13+name: release14+on:15+ push:16+ # Enable when testing release infrastructure on a branch.17+ # branches:18+ # - ag/release19+ tags:20+ - '[0-9]+.[0-9]+.[0-9]+'21+jobs:22+ create-release:23+ name: create-release24+ runs-on: ubuntu-latest25+ env:26+ # Set to force version number, e.g., when no tag exists.27+ # RG_VERSION: TEST-0.0.028+ steps:29+ - name: Create artifacts directory30+ run: mkdir artifacts31+32+ - name: Get the release version from the tag33+ if: env.RG_VERSION == ''34+ run: |35+ # Apparently, this is the right way to get a tag name. Really?36+ #37+ # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M102738+ echo "::set-env name=RG_VERSION::${GITHUB_REF#refs/tags/}"39+ echo "version is: ${{ env.RG_VERSION }}"40+41+ - name: Create GitHub release42+ id: release43+ uses: actions/create-release@v144+ env:45+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}46+ with:47+ tag_name: ${{ env.RG_VERSION }}48+ release_name: ripgrep ${{ env.RG_VERSION }}49+50+ - name: Save release upload URL to artifact51+ run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url52+53+ - name: Save version number to artifact54+ run: echo "${{ env.RG_VERSION }}" > artifacts/release-version55+56+ - name: Upload artifacts57+ uses: actions/upload-artifact@v158+ with:59+ name: artifacts60+ path: artifacts61+62+ build-release:63+ name: build-release64+ needs: ['create-release']65+ runs-on: ${{ matrix.os }}66+ env:67+ # For some builds, we use cross to test on 32-bit and big-endian68+ # systems.69+ CARGO: cargo70+ # When CARGO is set to CROSS, this is set to `--target matrix.target`.71+ TARGET_FLAGS:72+ # When CARGO is set to CROSS, TARGET_DIR includes matrix.target.73+ TARGET_DIR: ./target74+ # Emit backtraces on panics.75+ RUST_BACKTRACE: 176+ # Build static releases with PCRE2.77+ PCRE2_SYS_STATIC: 178+ strategy:79+ matrix:80+ build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc]81+ include:82+ - build: linux83+ os: ubuntu-18.0484+ rust: nightly85+ target: x86_64-unknown-linux-musl86+ - build: linux-arm87+ os: ubuntu-18.0488+ rust: nightly89+ target: arm-unknown-linux-gnueabihf90+ - build: macos91+ os: macos-latest92+ rust: nightly93+ target: x86_64-apple-darwin94+ - build: win-msvc95+ os: windows-201996+ rust: nightly97+ target: x86_64-pc-windows-msvc98+ - build: win-gnu99+ os: windows-2019100+ rust: nightly-x86_64-gnu101+ target: x86_64-pc-windows-gnu102+ - build: win32-msvc103+ os: windows-2019104+ rust: nightly105+ target: i686-pc-windows-msvc106+107+ steps:108+ - name: Checkout repository109+ uses: actions/checkout@v1110+ with:111+ fetch-depth: 1112+113+ - name: Install packages (Ubuntu)114+ if: matrix.os == 'ubuntu-18.04'115+ run: |116+ ci/ubuntu-install-packages117+118+ - name: Install packages (macOS)119+ if: matrix.os == 'macos-latest'120+ run: |121+ ci/macos-install-packages122+123+ - name: Install Rust124+ uses: actions-rs/toolchain@v1125+ with:126+ toolchain: ${{ matrix.rust }}127+ profile: minimal128+ override: true129+ target: ${{ matrix.target }}130+131+ - name: Use Cross132+ # if: matrix.os != 'windows-2019'133+ run: |134+ # FIXME: to work around bugs in latest cross release, install master.135+ # See: https://github.com/rust-embedded/cross/issues/357136+ cargo install --git https://github.com/rust-embedded/cross137+ echo "::set-env name=CARGO::cross"138+ echo "::set-env name=TARGET_FLAGS::--target ${{ matrix.target }}"139+ echo "::set-env name=TARGET_DIR::./target/${{ matrix.target }}"140+141+ - name: Show command used for Cargo142+ run: |143+ echo "cargo command is: ${{ env.CARGO }}"144+ echo "target flag is: ${{ env.TARGET_FLAGS }}"145+ echo "target dir is: ${{ env.TARGET_DIR }}"146+147+ - name: Get release download URL148+ uses: actions/download-artifact@v1149+ with:150+ name: artifacts151+ path: artifacts152+153+ - name: Set release upload URL and release version154+ shell: bash155+ run: |156+ release_upload_url="$(cat artifacts/release-upload-url)"157+ echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url"158+ echo "release upload url: $RELEASE_UPLOAD_URL"159+ release_version="$(cat artifacts/release-version)"160+ echo "::set-env name=RELEASE_VERSION::$release_version"161+ echo "release version: $RELEASE_VERSION"162+163+ - name: Build release binary164+ run: ${{ env.CARGO }} build --verbose --release --features pcre2 ${{ env.TARGET_FLAGS }}165+166+ - name: Strip release binary (linux and macos)167+ if: matrix.build == 'linux' || matrix.build == 'macos'168+ run: strip "target/${{ matrix.target }}/release/rg"169+170+ - name: Strip release binary (arm)171+ if: matrix.build == 'linux-arm'172+ run: |173+ docker run --rm -v \174+ "$PWD/target:/target:Z" \175+ rustembedded/cross:arm-unknown-linux-gnueabihf \176+ arm-linux-gnueabihf-strip \177+ /target/arm-unknown-linux-gnueabihf/release/rg178+179+ - name: Build archive180+ shell: bash181+ run: |182+ outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")"183+ staging="ripgrep-${{ env.RELEASE_VERSION }}-${{ matrix.target }}"184+ mkdir -p "$staging"/{complete,doc}185+186+ cp {README.md,COPYING,UNLICENSE,LICENSE-MIT} "$staging/"187+ cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/"188+ cp "$outdir"/{rg.bash,rg.fish,_rg.ps1} "$staging/complete/"189+ cp complete/_rg "$staging/complete/"190+191+ if [ "${{ matrix.os }}" = "windows-2019" ]; then192+ cp "target/${{ matrix.target }}/release/rg.exe" "$staging/"193+ 7z a "$staging.zip" "$staging"194+ echo "::set-env name=ASSET::$staging.zip"195+ else196+ # The man page is only generated on Unix systems. ¯\_(ツ)_/¯197+ cp "$outdir"/rg.1 "$staging/doc/"198+ cp "target/${{ matrix.target }}/release/rg" "$staging/"199+ tar czf "$staging.tar.gz" "$staging"200+ echo "::set-env name=ASSET::$staging.tar.gz"201+ fi202+203+ - name: Upload release archive204+ uses: actions/upload-release-asset@v1.0.1205+ env:206+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}207+ with:208+ upload_url: ${{ env.RELEASE_UPLOAD_URL }}209+ asset_path: ${{ env.ASSET }}210+ asset_name: ${{ env.ASSET }}211+ asset_content_type: application/octet-stream