ci: improve changelog generation #82
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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; | |
content = release.body; | |
} | |
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, | |
} | |
}) |