-
-
Notifications
You must be signed in to change notification settings - Fork 4
129 lines (117 loc) · 3.92 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
validate:
runs-on: "ubuntu-latest"
name: Validate
outputs:
PACKAGE_VERSION: ${{ steps.version-number.outputs.PACKAGE_VERSION }}
steps:
- name: 📥 Check out code from GitHub
uses: "actions/checkout@v4"
- name: 🛠️ Setup Python
uses: "actions/setup-python@v4"
with:
python-version: "3.x"
- name: ⚒️ HACS validation
uses: "hacs/action@main"
with:
category: "integration"
ignore: brands
- name: 🏠 Hassfest validation
uses: "home-assistant/actions/hassfest@master"
- name: 🔍 Get Commit Date
uses: actions/github-script@v6.4.0
id: author-date
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const commit_details = await github.git.getCommit({owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha});
return commit_details.data.author.date
- name: 🔍 Find Version Number
id: version-number
run: |
echo "VERSION_NUMBER=$(date -d ${{ steps.author-date.outputs.result }} +%Y.%m.%d.%H%M)" >> $GITHUB_ENV
PACKAGE_VERSION=$(cat "$PACKAGE_PROJECT" | grep -oPm1 "(?<=<PackageVersion>)[^<]+")
echo "PACKAGE_VERSION=$PACKAGE_VERSION.${{ github.run_number }}" >> $GITHUB_ENV
echo "::set-output name=PACKAGE_VERSION::$PACKAGE_VERSION.${{ github.run_number }}"
style:
runs-on: "ubuntu-latest"
name: Check style formatting
steps:
- name: 📥 Check out code from GitHub
uses: "actions/checkout@v4"
- name: 🛠️ Setup Python
uses: "actions/setup-python@v4"
with:
python-version: "3.x"
- name: 🛠️ Setup Python Requirements
run: python3 -m pip install black
- name: 🔍 Check style
run: black .
tests:
runs-on: "ubuntu-latest"
name: Run tests
steps:
- name: 📥 Check out code from GitHub
uses: "actions/checkout@v4"
- name: 🛠️ Setup Python
uses: "actions/setup-python@v4"
with:
python-version: "3.x"
# - name: Install requirements
# run: python3 -m pip install -r requirements_test.txt
# - name: Run tests
# run: |
# pytest \
# -qq \
# --timeout=9 \
# --durations=10 \
# -n auto \
# --cov custom_components.torque_logger \
# -o console_output_style=count \
# -p no:sugar \
# tests
deploy:
name: "release"
runs-on: "ubuntu-latest"
needs:
- validate
- style
- tests
# only create a release if pushed to main already
if: ${{ github.ref == 'refs/heads/main' && !contains(github.event.push.commits.*.message, 'readme') }}
environment:
name: hacs
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v4
- name: 🛠️ Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
cache: 'pip'
- name: ⚙️ Set version number
uses: maxgfr/actions-change-json@main
with:
key: 'version'
value: '${{ needs.validate.outputs.PACKAGE_VERSION }}'
path: custom_components/torque_logger/manifest.json
- name: 📦 Zip
run: |
cd ${{ github.workspace }}/custom_components/torque_logger
zip torque_logger.zip -r ./
- name: 🚀 Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: "v${{ needs.validate.outputs.PACKAGE_VERSION }}"
draft: false
prerelease: false
body: |
Changes in this Release
${{ github.event.head_commit.message }}
files: ${{ github.workspace }}/custom_components/torque_logger/torque_logger.zip