|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +env: |
| 9 | + CARGO_TERM_COLOR: always |
| 10 | + |
| 11 | +jobs: |
| 12 | + |
| 13 | + verify-version: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v2 |
| 17 | + - run: | |
| 18 | + tag="${GITHUB_REF#refs/tags/}" |
| 19 | + package_version="$(cargo read-manifest | jq --raw-output .version)" |
| 20 | + echo "Git tag name: ${tag}" |
| 21 | + echo "Cargo.toml version: ${package_version}" |
| 22 | + test "$tag" == "$package_version" |
| 23 | +
|
| 24 | + # Run the tests and create a fresh cache before releasing. Make sure that the |
| 25 | + # same code that was tested is what gets released. |
| 26 | + test: |
| 27 | + runs-on: ${{ matrix.os }} |
| 28 | + strategy: |
| 29 | + matrix: |
| 30 | + os: |
| 31 | + - ubuntu-latest |
| 32 | + - macos-latest |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v2 |
| 35 | + - uses: actions/cache@v2 |
| 36 | + with: |
| 37 | + path: | |
| 38 | + ~/.cargo/registry |
| 39 | + ~/.cargo/git |
| 40 | + target |
| 41 | + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ secrets.CI_CACHE_VERSION }} |
| 42 | + - run: cargo test |
| 43 | + |
| 44 | + publish-binary: |
| 45 | + needs: |
| 46 | + - verify-version |
| 47 | + - test |
| 48 | + runs-on: ${{ matrix.os }} |
| 49 | + strategy: |
| 50 | + matrix: |
| 51 | + os: |
| 52 | + - ubuntu-latest |
| 53 | + - macos-latest |
| 54 | + include: |
| 55 | + - os: macos-latest |
| 56 | + artifact_prefix: macos |
| 57 | + target: x86_64-apple-darwin |
| 58 | + - os: ubuntu-latest |
| 59 | + artifact_prefix: linux |
| 60 | + target: x86_64-unknown-linux-gnu |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v2 |
| 63 | + - uses: actions/cache@v2 |
| 64 | + with: |
| 65 | + path: | |
| 66 | + ~/.cargo/registry |
| 67 | + ~/.cargo/git |
| 68 | + target |
| 69 | + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ secrets.CI_CACHE_VERSION }} |
| 70 | + - run: cargo build --release --target ${{ matrix.target }} |
| 71 | + - name: package binary |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + cd target/${{ matrix.target }}/release |
| 75 | + strip ${{ github.event.repository.name }} |
| 76 | + tar czvf \ |
| 77 | + ${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.tar.gz \ |
| 78 | + ${{ github.event.repository.name }} |
| 79 | + shasum -a 256 ${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.tar.gz \ |
| 80 | + > ${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.sha256 |
| 81 | + - name: publish release to github |
| 82 | + uses: softprops/action-gh-release@v1 |
| 83 | + with: |
| 84 | + files: | |
| 85 | + target/${{ matrix.target }}/release/${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.tar.gz |
| 86 | + target/${{ matrix.target }}/release/${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.sha256 |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + |
| 90 | + publish-crate: |
| 91 | + needs: |
| 92 | + - verify-version |
| 93 | + - test |
| 94 | + runs-on: ubuntu-latest |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v2 |
| 97 | + - uses: actions/cache@v2 |
| 98 | + with: |
| 99 | + path: | |
| 100 | + ~/.cargo/registry |
| 101 | + ~/.cargo/git |
| 102 | + target |
| 103 | + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ secrets.CI_CACHE_VERSION }} |
| 104 | + - run: cargo publish --token ${{ secrets.CARGO_API_TOKEN }} --allow-dirty |
0 commit comments