1+ # This GitHub action workflow is meant to be copyable to any repo that have the same structure.
2+ # - Your integration exist under custom_components/{INTEGRATION_NAME}/[integration files]
3+ # - You are using GitHub releases to publish new versions
4+ # - You have a INTEGRATION_VERSION constant in custom_components/{INTEGRATION_NAME}/const.py
5+
6+ name : Release Workflow
7+
8+ on :
9+ release :
10+ types : [published]
11+
12+ jobs :
13+ release :
14+ name : Release
15+ runs-on : ubuntu-latest
16+ steps :
17+ - name : 📥 Checkout the repository
18+ uses : actions/checkout@v2
19+
20+ - name : 🔢 Get release version
21+ id : version
22+ uses : home-assistant/actions/helpers/version@master
23+
24+ - name : ℹ️ Get integration information
25+ id : information
26+ run : |
27+ name=$(find custom_components/ -type d -maxdepth 1 | tail -n 1 | cut -d "/" -f2)
28+ echo "::set-output name=name::$name"
29+
30+ - name : 🖊️ Set version number
31+ run : |
32+ sed -i '/INTEGRATION_VERSION = /c\INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' \
33+ "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py"
34+ jq '.version = "${{ steps.version.outputs.version }}"' \
35+ "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json" > tmp \
36+ && mv -f tmp "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json"
37+
38+ - name : 👀 Validate data
39+ run : |
40+ if ! grep -q 'INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py; then
41+ echo "The version in custom_components/${{ steps.information.outputs.name }}/const.py was not correct"
42+ cat ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py | grep INTEGRATION_VERSION
43+ exit 1
44+ fi
45+ manifestversion=$(jq -r '.version' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json)
46+ if [ "$manifestversion" != "${{ steps.version.outputs.version }}" ]; then
47+ echo "The version in custom_components/${{ steps.information.outputs.name }}/manifest.json was not correct"
48+ echo "$manifestversion"
49+ exit 1
50+ fi
51+
52+ - name : 📦 Create zip file for the integration
53+ run : |
54+ cd "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}"
55+ zip ${{ steps.information.outputs.name }}.zip -r ./
56+
57+ - name : 📤 Upload the zip file as a release asset
58+ uses : actions/upload-release-asset@v1
59+ env :
60+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61+ with :
62+ upload_url : ${{ github.event.release.upload_url }}
63+ asset_path : " ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/${{ steps.information.outputs.name }}.zip"
64+ asset_name : ${{ steps.information.outputs.name }}.zip
65+ asset_content_type : application/zip
0 commit comments