blob: 3e4cacca715302d8444c906c6be99c4a563d53b2 [file]
# 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-[0-9]+.[0-9]+.[0-9]+'
env:
GITHUB_TOKEN: ${{ github.token }}
CARGO_TERM_COLOR: always
jobs:
tag:
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 matche 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
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- 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