-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (169 loc) · 6.21 KB
/
release.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
---
name: Publish Images and Release
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
release:
types: [published]
# schedule:
# - cron: "0 2 * * *"
push:
branches:
- master
# - 'releases/**'
# tags:
# - v*
# Release -> build and push beta/stable
# Push to master -> build and push 'edge'
permissions:
contents: read
jobs:
deploy-docker:
name: Build and publish Typedaemon # ${{ matrix.image.title}}
if: github.repository == 'matchlighter/typedaemon'
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
# continue-on-error: ${{ matrix.image.title == 'lint' }}
strategy:
fail-fast: false
# matrix:
# image:
# - title: "ha-addon"
# suffix: "hassio"
# target: "hassio"
# baseimg: "hassio"
# - title: "docker"
# suffix: ""
# target: "docker"
# baseimg: "docker"
# - title: "lint"
# suffix: "lint"
# target: "lint"
# baseimg: "docker"
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Log in to the GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: check
uses: EndBug/version-check@v2
with:
diff-search: true
token: ${{ secrets.GITHUB_TOKEN }}
# You can use this to make the action use the current version (either from the
# local file or the provided URL, see the `file-url` option) as either the added
# or deleted version.
# Accepted values are 'new' (if you want that version to be the "added" one) and
# 'old' (to make it the "deleted" one).
# Default: ''
# assume-same-version: old
- name: Generate short tags
id: tags
run: |
script/generate_tags.py --package-version ${{ steps.check.outputs.version }} --package-version-changed ${{ steps.check.outputs.changed }}
# --suffix "${{ matrix.image.suffix }}"
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
# target: ${{ matrix.image.target }}
push: true
# yamllint disable rule:line-length
cache-from: type=registry,ref=ghcr.io/${{ steps.tags.outputs.image }}:cache-${{ steps.tags.outputs.channel }}
cache-to: type=registry,ref=ghcr.io/${{ steps.tags.outputs.image }}:cache-${{ steps.tags.outputs.channel }},mode=max
# yamllint enable rule:line-length
tags: ${{ steps.tags.outputs.tags }}
# BASEIMGTYPE=${{ matrix.image.baseimg }}
build-args: |
BUILD_VERSION=${{ steps.tags.outputs.version }}
BUILD_CHANNEL=${{ steps.tags.outputs.channel }}
outputs:
version: ${{ steps.tags.outputs.version }}
channel: ${{ steps.tags.outputs.channel }}
create-release:
if: github.repository == 'matchlighter/typedaemon' && github.event_name != 'release' && needs.deploy-docker.outputs.channel == 'release'
needs: [deploy-docker]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --prune --unshallow --tags
- name: Generate Release Message
id: message
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
script: |
const last_release_resp = await github.rest.repos.getLatestRelease({
owner: "matchlighter",
repo: "typedaemon",
});
const last_release = last_release_resp?.data;
const diff = last_release ? `refs/tags/${last_release.tag_name}..HEAD` : "";
let message = '';
await exec.exec(`git log ${diff} --pretty=format:"- %h %s"`, [], {
listeners: {
stdout: (data) => { message += data.toString(); },
}
})
core.setOutput("body", message.trim());
- name: Release
id: release
uses: softprops/action-gh-release@v1
with:
body: ${{ steps.message.outputs.body }}
tag_name: ${{ needs.deploy-docker.outputs.version }}
target_commitish: ${{ github.ref }}
prerelease: ${{ needs.deploy-docker.outputs.channel != 'release' }}
outputs:
body: ${{ steps.message.outputs.body }}
release_id: ${{ steps.release.outputs.id }}
deploy-ha-addon-repo:
if: ${{ !failure() && github.repository == 'matchlighter/typedaemon' && needs.deploy-docker.outputs.channel == 'release' }}
runs-on: ubuntu-latest
needs: [deploy-docker, create-release]
steps:
- name: Trigger Workflow
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
script: |
let content = ${{ toJSON(github.event.release.body) }} || ${{ toJSON(needs.deploy-docker.outputs.body) }};
if (!content) {
const release_resp = await github.rest.repos.getRelease({
owner: "matchlighter",
repo: "typedaemon",
release_id: ${{ needs.create-release.outputs.release_id }},
});
const release = release_resp.data;
console.log(release);
content = release.body;
}
console.log(content);
await github.rest.actions.createWorkflowDispatch({
owner: "matchlighter",
repo: "typedaemon-hassio",
workflow_id: "bump-version.yml",
ref: "master",
inputs: {
version: "${{ needs.deploy-docker.outputs.version }}",
content,
}
})