|
| 1 | +name: CI |
| 2 | + |
| 3 | +# Controls when the action will run. Triggers the workflow on push or pull |
| 4 | +# request events but only for the main branch. |
| 5 | +on: |
| 6 | + push: |
| 7 | + # Run on the main branch. |
| 8 | + branches: |
| 9 | + - main |
| 10 | + - ci |
| 11 | + tags: |
| 12 | + - "v*" |
| 13 | + pull_request: |
| 14 | + # Only run on pull requests against main. |
| 15 | + branches: [main] |
| 16 | + |
| 17 | +jobs: |
| 18 | + # We run this job first, to create any GitHub release that we might need. |
| 19 | + # Creating a release can only be done once, so we need to split it out from |
| 20 | + # other jobs. |
| 21 | + create_release: |
| 22 | + name: Create release (if needed) |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + release_version: ${{ steps.extract_release_version.outputs.release_version }} |
| 26 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 27 | + steps: |
| 28 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + - name: Extract release version |
| 31 | + id: extract_release_version |
| 32 | + run: | |
| 33 | + release_version="$(echo '${{ github.ref }}' | sed 's,^.*/\([^/]*\)$,\1,; s,^v,,' )" |
| 34 | + echo Release version: $release_version |
| 35 | + echo "::set-output name=release_version::$release_version" |
| 36 | + - name: Extract release body from CHANGELOG.md |
| 37 | + id: extract_release_body |
| 38 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 39 | + # Use `clparse` to parse `CHANGELOG.md` and extract release notes. |
| 40 | + run: | |
| 41 | + curl -sLO https://github.com/marcaddeo/clparse/releases/download/0.8.0/clparse-0.8.0-x86_64-unknown-linux-musl.tar.gz |
| 42 | + tar xzf clparse*.tar.gz |
| 43 | + sudo cp clparse /usr/local/bin |
| 44 | + rm -rf clparse* |
| 45 | + clparse -f json CHANGELOG.md | \ |
| 46 | + jq ".releases[] | select(.version == \"${{ steps.extract_release_version.outputs.release_version }}\") | { title: \"\", description: \"\", releases: [.] }" | \ |
| 47 | + clparse - | \ |
| 48 | + tail -n +3 > RELEASE_BODY.md |
| 49 | + - name: "Make release" |
| 50 | + id: create_release |
| 51 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 52 | + uses: actions/create-release@v1 |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + with: |
| 56 | + tag_name: ${{ github.ref }} |
| 57 | + release_name: "${{ steps.extract_release_version.outputs.release_version }}" |
| 58 | + body_path: RELEASE_BODY.md |
| 59 | + |
| 60 | + # We use a matrix to run our build on every supported platform. |
| 61 | + build: |
| 62 | + name: "Build" |
| 63 | + |
| 64 | + needs: |
| 65 | + - create_release |
| 66 | + |
| 67 | + strategy: |
| 68 | + matrix: |
| 69 | + # target: Official name of system to compile for. |
| 70 | + # host: Official name of system doing the compiling. |
| 71 | + # cargo: Should we use regular cargo, or the cross wrapper for cross-compiling? |
| 72 | + # os: GitHub CI OS image to use on runner. |
| 73 | + include: |
| 74 | + - target: x86_64-unknown-linux-musl |
| 75 | + host: x86_64-unknown-linux-musl |
| 76 | + cargo: cross |
| 77 | + os: ubuntu-latest |
| 78 | + - target: x86_64-apple-darwin |
| 79 | + host: x86_64-apple-darwin |
| 80 | + cargo: cargo |
| 81 | + os: macos-latest |
| 82 | + - target: aarch64-apple-darwin |
| 83 | + host: x86_64-apple-darwin |
| 84 | + cargo: cargo |
| 85 | + os: macos-latest |
| 86 | + |
| 87 | + runs-on: ${{ matrix.os }} |
| 88 | + |
| 89 | + steps: |
| 90 | + - name: Install Rust toolchain |
| 91 | + uses: actions-rs/toolchain@v1 |
| 92 | + with: |
| 93 | + profile: minimal |
| 94 | + # We track latest stable Rust instead of hardcoding it because it |
| 95 | + # virtually never breaks old code. |
| 96 | + toolchain: stable |
| 97 | + components: rustfmt, clippy |
| 98 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 99 | + - uses: actions/checkout@v2 |
| 100 | + - name: Check source formatting and warnings |
| 101 | + run: | |
| 102 | + cargo fmt -- --check |
| 103 | + cargo clippy -- -D warnings |
| 104 | + - name: Check policy |
| 105 | + run: | |
| 106 | + version=0.11.0 |
| 107 | + basename=cargo-deny-$version-${{ matrix.host }} |
| 108 | + curl -fLO https://github.com/EmbarkStudios/cargo-deny/releases/download/$version/$basename.tar.gz |
| 109 | + tar xf $basename.tar.gz |
| 110 | + mv $basename/cargo-deny /usr/local/bin/ |
| 111 | + rm -rf $basename $basename.tar.gz |
| 112 | + cargo deny check |
| 113 | + - name: Test |
| 114 | + run: | |
| 115 | + cargo test |
| 116 | + - name: Install cargo cross (if needed) |
| 117 | + if: ${{ matrix.cargo == 'cross' }} |
| 118 | + # Note that this will not work for Rust programs using openssl or libpq. |
| 119 | + run: | |
| 120 | + version=v0.2.1 |
| 121 | + basename=cross-$version-${{ matrix.host }} |
| 122 | + curl -fLO https://github.com/rust-embedded/cross/releases/download/$version/$basename.tar.gz |
| 123 | + tar xf $basename.tar.gz |
| 124 | + mv cross /usr/local/bin/ |
| 125 | + rm -rf $basename.tar.gz |
| 126 | + - name: Build binaries |
| 127 | + run: | |
| 128 | + ${{ matrix.cargo }} build --release --target ${{ matrix.target }} |
| 129 | + # If we have a code-signing identity, we could use it like this. |
| 130 | + # |
| 131 | + # - name: Sign binaries (if needed) |
| 132 | + # if: ${{ contains(matrix.target, 'apple') }} |
| 133 | + # run: | |
| 134 | + # codesign --force -s $YOUR_IDENTITY_HERE target/${{ matrix.target }}/release/geocode-csv |
| 135 | + - name: Build release |
| 136 | + id: build_release |
| 137 | + run: | |
| 138 | + release_file=geocode-csv-${{ matrix.target }}-${{ needs.create_release.outputs.release_version }}.zip |
| 139 | + zip -j $release_file target/${{ matrix.target }}/release/geocode-csv |
| 140 | + echo "::set-output name=release_file::$release_file" |
| 141 | + - name: Upload Release Asset |
| 142 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 143 | + uses: actions/upload-release-asset@v1 |
| 144 | + env: |
| 145 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + with: |
| 147 | + upload_url: ${{ needs.create_release.outputs.upload_url }} |
| 148 | + asset_path: ./${{ steps.build_release.outputs.release_file }} |
| 149 | + asset_name: ${{ steps.build_release.outputs.release_file }} |
| 150 | + asset_content_type: application/zip |
0 commit comments