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+ - name : 🖊️ Set version number
30+ run : |
31+ sed -i '/INTEGRATION_VERSION = /c\INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' \
32+ "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py"
33+ jq '.version = "${{ steps.version.outputs.version }}"' \
34+ "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json" > tmp \
35+ && mv -f tmp "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json"
36+ - name : 👀 Validate data
37+ run : |
38+ if ! grep -q 'INTEGRATION_VERSION = "${{ steps.version.outputs.version }}"' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py; then
39+ echo "The version in custom_components/${{ steps.information.outputs.name }}/const.py was not correct"
40+ cat ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/const.py | grep INTEGRATION_VERSION
41+ exit 1
42+ fi
43+ manifestversion=$(jq -r '.version' ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/manifest.json)
44+ if [ "$manifestversion" != "${{ steps.version.outputs.version }}" ]; then
45+ echo "The version in custom_components/${{ steps.information.outputs.name }}/manifest.json was not correct"
46+ echo "$manifestversion"
47+ exit 1
48+ fi
49+ - name : 📦 Create zip file for the integration
50+ run : |
51+ cd "${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}"
52+ zip ${{ steps.information.outputs.name }}.zip -r ./
53+ - name : 📤 Upload the zip file as a release asset
54+ uses : actions/upload-release-asset@v1
55+ env :
56+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57+ with :
58+ upload_url : ${{ github.event.release.upload_url }}
59+ asset_path : " ${{ github.workspace }}/custom_components/${{ steps.information.outputs.name }}/${{ steps.information.outputs.name }}.zip"
60+ asset_name : ${{ steps.information.outputs.name }}.zip
61+ asset_content_type : application/zip
0 commit comments