add home-assistant version badge #40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: "Release" | |
on: | |
push: | |
branches: | |
- "master" | |
permissions: | |
contents: "write" | |
jobs: | |
check_version_update: | |
runs-on: "ubuntu-latest" | |
outputs: | |
version: ${{ steps.galaxy_yml_version.outputs.value }} | |
is_updated: ${{ steps.compare_versions.outputs.value }} | |
steps: | |
- uses: "actions/checkout@v4" | |
- name: "Install PyYAML" | |
run: pip install pyyaml | |
- name: "Read version from galaxy.yml" | |
id: galaxy_yml_version | |
run: | | |
import yaml | |
import os | |
with open('galaxy.yml', 'r') as file: | |
data = yaml.safe_load(file) | |
with open(os.environ['GITHUB_OUTPUT'], 'a') as output_file: | |
output_file.write(f"value={data['version']}\n") | |
shell: "python" | |
- name: "Compare with latest git tag" | |
id: compare_versions | |
run: | | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo 'v0.0.0') | |
if [[ "${{ steps.galaxy_yml_version.outputs.value }}" != "$latest_tag" ]]; then | |
echo "value=true" >> $GITHUB_OUTPUT | |
else | |
echo "value=false" >> $GITHUB_OUTPUT | |
fi | |
publish: | |
runs-on: "ubuntu-latest" | |
needs: check_version_update | |
if: needs.check_version_update.outputs.is_updated == 'true' | |
steps: | |
- uses: "actions/checkout@v4" | |
- name: "Build the Collection" | |
run: ansible-galaxy collection build | |
- name: "Publish to Galaxy" | |
run: >- | |
ansible-galaxy collection publish | |
--api-key ${{ secrets.GALAXY_API_KEY }} | |
./artyorsh-smarthome-${{ needs.check_version_update.outputs.version }}.tar.gz | |
- name: "Publish a new tag" | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git tag ${{ needs.check_version_update.outputs.version }} | |
git push origin ${{ needs.check_version_update.outputs.version }} |