| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| name: publish_cli |
| on: |
| push: |
| tags: |
| - 'iggy-cli-*' |
| |
| env: |
| GITHUB_TOKEN: ${{ github.token }} |
| CARGO_TERM_COLOR: always |
| |
| jobs: |
| validate: |
| if: startsWith(github.ref, 'refs/tags/iggy-cli-') |
| runs-on: ubuntu-latest |
| steps: |
| - name: Extract tag name |
| id: extract |
| run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV |
| |
| - name: Validate tag format |
| run: | |
| TAG=${TAG} |
| if [[ ! "$TAG" =~ ^iggy-cli-([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]]; then |
| echo "Tag $TAG does not match strict semver format (iggy-cli-X.Y.Z where 0 <= X,Y,Z <= 999)" |
| exit 1 |
| fi |
| echo "Valid tag: $TAG" |
| |
| tag: |
| needs: validate |
| runs-on: ubuntu-latest |
| steps: |
| - name: Checkout code |
| uses: actions/checkout@v4 |
| with: |
| fetch-depth: 0 |
| |
| - name: Extract tag name |
| id: extract_tag |
| run: | |
| tag=${GITHUB_REF#refs/tags/} |
| echo "tag_name=$tag" >> "$GITHUB_OUTPUT" |
| echo "::notice ::Tag that triggered the workflow: $tag" |
| |
| - name: Extract iggy-cli version from Cargo.toml |
| id: extract_version |
| run: | |
| version=$(cargo pkgid -p iggy-cli | cut -d@ -f2) |
| echo "iggy_cli_version=$version" >> "$GITHUB_OUTPUT" |
| echo "::notice ::Version from Cargo.toml $version" |
| |
| - name: Check if version from Cargo.toml is the same as the tag |
| id: check_git_tag |
| run: | |
| if [[ "iggy-cli-${{ steps.extract_version.outputs.iggy_cli_version }}" == "${{ steps.extract_tag.outputs.tag_name }}" ]]; |
| then |
| echo "::notice ::Tag ${{ steps.extract_tag.outputs.tag_name }} matches the version in Cargo.toml" |
| echo "tag_matches=true" >> "$GITHUB_OUTPUT" |
| else |
| echo "::warning ::Tag ${{ steps.extract_tag.outputs.tag_name }} does not match the version from Cargo.toml" |
| echo "tag_matches=false" >> "$GITHUB_OUTPUT" |
| fi |
| |
| outputs: |
| iggy_cli_version: ${{ steps.extract_tag.outputs.tag_name }} |
| tag_created: ${{ steps.check_git_tag.outputs.tag_matches }} |
| |
| publish: |
| name: Publish CLI on crates.io |
| needs: tag |
| if: ${{ needs.tag.outputs.tag_created == 'true' }} |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v4 |
| |
| - run: | |
| rustup toolchain add --profile=minimal stable |
| rustup override set stable |
| |
| - name: publish |
| run: | |
| cargo login "${{ secrets.CARGO_REGISTRY_TOKEN }}" |
| cargo publish -p iggy-cli |
| |
| github_release: |
| uses: ./.github/workflows/release_cli.yml |
| needs: tag |
| if: ${{ needs.tag.outputs.tag_created == 'true' }} |
| with: |
| tag_name: "iggy-cli-${{ needs.tag.outputs.iggy_cli_version }}" |
| |
| finalize_cli: |
| runs-on: ubuntu-latest |
| needs: |
| - publish |
| - github_release |
| if: always() |
| steps: |
| - uses: actions/checkout@v4 |
| - name: Everything is fine |
| if: ${{ !(contains(needs.*.result, 'failure')) }} |
| run: exit 0 |
| - name: Something went wrong |
| if: ${{ contains(needs.*.result, 'failure') }} |
| uses: JasonEtco/create-an-issue@v2 |
| env: |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| GITHUB_BOT_CONTEXT_STRING: "publish to crates.io" |
| with: |
| filename: .github/BOT_ISSUE_TEMPLATE.md |