Skip to content

Commit bd80605

Browse files
edenhausludeeus
andauthored
Add Version + Release action (#11)
Co-authored-by: Joakim Sørensen <[email protected]>
1 parent ccb3a68 commit bd80605

File tree

7 files changed

+92
-7
lines changed

7 files changed

+92
-7
lines changed

.github/workflows/hassfest.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Validate with hassfest
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
schedule:
9+
- cron: "0 0 * * *"
10+
11+
jobs:
12+
validate:
13+
runs-on: "ubuntu-latest"
14+
steps:
15+
- uses: "actions/checkout@v2"
16+
- uses: home-assistant/actions/hassfest@master

.github/workflows/release.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

custom_components/readme/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from integrationhelper import Logger
1919
from integrationhelper.const import CC_STARTUP_VERSION
2020

21-
from .const import DOMAIN_DATA, DOMAIN, ISSUE_URL, REQUIRED_FILES, VERSION
21+
from .const import DOMAIN_DATA, DOMAIN, ISSUE_URL, REQUIRED_FILES, INTEGRATION_VERSION
2222

2323
CONFIG_SCHEMA = vol.Schema(
2424
{DOMAIN: vol.Schema({vol.Optional("convert_lovelace"): cv.boolean})},
@@ -41,7 +41,7 @@ async def async_setup(hass, config):
4141
# Print startup message
4242
Logger("custom_components.readme").info(
4343
CC_STARTUP_VERSION.format(
44-
name=DOMAIN.capitalize(), version=VERSION, issue_link=ISSUE_URL
44+
name=DOMAIN.capitalize(), version=INTEGRATION_VERSION, issue_link=ISSUE_URL
4545
)
4646
)
4747

@@ -79,7 +79,7 @@ async def async_setup_entry(hass, config_entry):
7979
# Print startup message
8080
Logger("custom_components.readme").info(
8181
CC_STARTUP_VERSION.format(
82-
name=DOMAIN.capitalize(), version=VERSION, issue_link=ISSUE_URL
82+
name=DOMAIN.capitalize(), version=INTEGRATION_VERSION, issue_link=ISSUE_URL
8383
)
8484
)
8585

custom_components/readme/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Base component constants
33
DOMAIN = "readme"
44
DOMAIN_DATA = f"{DOMAIN}_data"
5-
VERSION = "0.2.1"
5+
INTEGRATION_VERSION = "0.0.0"
66
REQUIRED_FILES = [
77
"translations/en.json",
88
"const.py",
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"domain": "readme",
33
"name": "Generate readme",
4+
"version": "0.0.0",
45
"documentation": "https://github.com/custom-components/readme",
6+
"issue_tracker": "https://github.com/custom-components/issues",
57
"dependencies": [],
68
"config_flow": true,
79
"codeowners": [
@@ -10,5 +12,5 @@
1012
"requirements": [
1113
"integrationhelper==0.2.2"
1214
],
13-
"homeassistant": "0.97.0"
14-
}
15+
"iot_class": "calculated"
16+
}

custom_components/readme/translations/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"config": {
3-
"title": "Generate readme",
43
"step": {
54
"user": {
65
"title": "Generate readme",

hacs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "Generate readme",
3+
"iot_class": "calculated",
4+
"zip_release": true,
5+
"filename": "readme.zip",
6+
"hide_default_branch": true
7+
}

0 commit comments

Comments
 (0)