|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v[0-9]+.[0-9]+.[0-9]+* |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + RUST_TARGET: x86_64-unknown-linux-musl |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-linux: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v2 |
| 20 | + - name: Build toml cli |
| 21 | + # uses: juankaram/rust-musl-action@master |
| 22 | + uses: gmiam/rust-musl-action@master |
| 23 | + with: |
| 24 | + args: cargo build --target $RUST_TARGET --release |
| 25 | + - name: store-artifacts |
| 26 | + uses: actions/upload-artifact@v2 |
| 27 | + with: |
| 28 | + if-no-files-found: error |
| 29 | + name: toml-artifacts-linux |
| 30 | + path: | |
| 31 | + target/${{ env.RUST_TARGET }}/release/toml |
| 32 | +
|
| 33 | + prepare-tarball-linux: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + needs: [build-linux] |
| 36 | + steps: |
| 37 | + - name: download artifacts |
| 38 | + uses: actions/download-artifact@v2 |
| 39 | + with: |
| 40 | + name: toml-artifacts-linux |
| 41 | + path: toml-cli |
| 42 | + - name: prepare release tarball |
| 43 | + run: | |
| 44 | + tag=$(echo $GITHUB_REF | cut -d/ -f3-) |
| 45 | + tarball="toml-cli-$tag-linux-amd64.tgz" |
| 46 | + chmod +x toml-cli/* |
| 47 | + tar cf - toml-cli | gzip > ${tarball} |
| 48 | + echo "tarball=${tarball}" >> $GITHUB_ENV |
| 49 | +
|
| 50 | + shasum="$tarball.sha256sum" |
| 51 | + sha256sum $tarball > $shasum |
| 52 | + echo "tarball_shasum=${shasum}" >> $GITHUB_ENV |
| 53 | + - name: store-artifacts |
| 54 | + uses: actions/upload-artifact@v2 |
| 55 | + with: |
| 56 | + name: release-tarball |
| 57 | + path: | |
| 58 | + ${{ env.tarball }} |
| 59 | + ${{ env.tarball_shasum }} |
| 60 | +
|
| 61 | + create-release: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + needs: [prepare-tarball-linux] |
| 64 | + steps: |
| 65 | + - name: download artifacts |
| 66 | + uses: actions/download-artifact@v2 |
| 67 | + with: |
| 68 | + name: release-tarball |
| 69 | + path: tarballs |
| 70 | + - name: prepare release env |
| 71 | + run: | |
| 72 | + echo "tarballs<<EOF" >> $GITHUB_ENV |
| 73 | + for I in $(ls tarballs);do echo "tarballs/${I}" >> $GITHUB_ENV; done |
| 74 | + echo "EOF" >> $GITHUB_ENV |
| 75 | + tag=$(echo $GITHUB_REF | cut -d/ -f3-) |
| 76 | + echo "tag=${tag}" >> $GITHUB_ENV |
| 77 | + cat $GITHUB_ENV |
| 78 | + - name: push release |
| 79 | + if: github.event_name == 'push' |
| 80 | + uses: softprops/action-gh-release@v1 |
| 81 | + with: |
| 82 | + name: "Toml cli ${{ env.tag }}" |
| 83 | + body: | |
| 84 | + "Toml cli release ${{ env.tag }}" |
| 85 | + generate_release_notes: true |
| 86 | + files: | |
| 87 | + ${{ env.tarballs }} |
| 88 | +
|
| 89 | + publish-image: |
| 90 | + runs-on: ubuntu-latest |
| 91 | + needs: [build-linux] |
| 92 | + steps: |
| 93 | + - name: Checkout repository |
| 94 | + uses: actions/checkout@v2 |
| 95 | + - name: Log in to the container registry |
| 96 | + uses: docker/login-action@v2 |
| 97 | + with: |
| 98 | + registry: ${{ env.REGISTRY }} |
| 99 | + username: ${{ github.actor }} |
| 100 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + - name: download artifacts |
| 102 | + uses: actions/download-artifact@v2 |
| 103 | + with: |
| 104 | + name: toml-artifacts-linux |
| 105 | + path: misc |
| 106 | + - name: Extract metadata (tags, labels) for Docker |
| 107 | + id: meta |
| 108 | + uses: docker/metadata-action@v4 |
| 109 | + with: |
| 110 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 111 | + - name: build and push toml cli image |
| 112 | + uses: docker/build-push-action@v3 |
| 113 | + with: |
| 114 | + context: misc |
| 115 | + file: misc/Dockerfile |
| 116 | + push: true |
| 117 | + tags: ${{ steps.meta.outputs.tags }} |
| 118 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments