|
| 1 | +on: |
| 2 | + push: |
| 3 | + tags: |
| 4 | + - "starknet/v*.*.*" |
| 5 | + - "starknet-*/v*.*.*" |
| 6 | + |
| 7 | +name: "Release" |
| 8 | + |
| 9 | +jobs: |
| 10 | + # Just in case we accidentally release something not on master. |
| 11 | + commit-branch-check: |
| 12 | + name: "Check commit branch" |
| 13 | + runs-on: "ubuntu-latest" |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: "Checkout source code" |
| 17 | + uses: "actions/checkout@v3" |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: "Check if commit is on master" |
| 22 | + run: | |
| 23 | + COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }}) |
| 24 | + GREP_OUTPUT=$(git log origin/master --format=%H | grep "$COMMIT_HASH") |
| 25 | +
|
| 26 | + if [ -z "$GREP_OUTPUT" ]; then |
| 27 | + echo "Cannot release commits not on the master branch" |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | +
|
| 31 | + crate-version-check: |
| 32 | + name: "Check crate version" |
| 33 | + runs-on: "ubuntu-latest" |
| 34 | + needs: ["commit-branch-check"] |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: "Checkout source code" |
| 38 | + uses: "actions/checkout@v3" |
| 39 | + |
| 40 | + - name: "Derive crate info from Git tag" |
| 41 | + run: | |
| 42 | + FULL_REF="${{ github.ref }}" |
| 43 | + REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$" |
| 44 | + [[ $FULL_REF =~ $REGEX ]]; |
| 45 | +
|
| 46 | + echo "CRATE=${BASH_REMATCH[1]}" >> $GITHUB_ENV |
| 47 | + echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV |
| 48 | +
|
| 49 | + - name: "Check against Cargo.toml" |
| 50 | + run: | |
| 51 | + if [ "starknet" != "$CRATE" ]; then |
| 52 | + cd $CRATE |
| 53 | + fi |
| 54 | +
|
| 55 | + GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${VERSION}\"$") |
| 56 | +
|
| 57 | + if [ -z "$GREP_OUTPUT" ]; then |
| 58 | + echo "Crate version mismatch" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + build: |
| 63 | + name: "Build for ${{ matrix.os }}" |
| 64 | + runs-on: "${{ matrix.os }}" |
| 65 | + needs: ["crate-version-check"] |
| 66 | + |
| 67 | + strategy: |
| 68 | + matrix: |
| 69 | + os: |
| 70 | + - "ubuntu-latest" |
| 71 | + - "windows-latest" |
| 72 | + - "macos-latest" |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: "Checkout source code" |
| 76 | + uses: "actions/checkout@v3" |
| 77 | + |
| 78 | + - name: "Setup stable toolchain" |
| 79 | + uses: "actions-rs/toolchain@v1" |
| 80 | + with: |
| 81 | + toolchain: "stable" |
| 82 | + profile: "minimal" |
| 83 | + override: true |
| 84 | + |
| 85 | + - name: "Derive crate info from Git tag" |
| 86 | + run: | |
| 87 | + FULL_REF="${{ github.ref }}" |
| 88 | + REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$" |
| 89 | + [[ $FULL_REF =~ $REGEX ]]; |
| 90 | +
|
| 91 | + echo "CRATE=${BASH_REMATCH[1]}" >> $GITHUB_ENV |
| 92 | + echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV |
| 93 | +
|
| 94 | + - name: "Build crate" |
| 95 | + run: | |
| 96 | + cargo build --package $CRATE --all-targets |
| 97 | +
|
| 98 | + crates-io-release: |
| 99 | + name: "Release to crates.io" |
| 100 | + runs-on: "ubuntu-latest" |
| 101 | + |
| 102 | + # We don't want to publish something that wouldn't even build to crates.io |
| 103 | + needs: ["build"] |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: "Checkout source code" |
| 107 | + uses: "actions/checkout@v3" |
| 108 | + |
| 109 | + - name: "Derive crate info from Git tag" |
| 110 | + run: | |
| 111 | + FULL_REF="${{ github.ref }}" |
| 112 | + REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$" |
| 113 | + [[ $FULL_REF =~ $REGEX ]]; |
| 114 | +
|
| 115 | + echo "CRATE=${BASH_REMATCH[1]}" >> $GITHUB_ENV |
| 116 | + echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV |
| 117 | +
|
| 118 | + - name: "Login to crates.io" |
| 119 | + run: | |
| 120 | + cargo login ${{ secrets.CRATES_IO_API_TOKEN }} |
| 121 | +
|
| 122 | + - name: "Public crate" |
| 123 | + run: | |
| 124 | + cargo publish --package $CRATE |
0 commit comments