Skip to content

Commit

Permalink
work on release automation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matchlighter committed Dec 28, 2023
1 parent c3fd00a commit a727618
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 68 deletions.
80 changes: 31 additions & 49 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,20 @@ on:
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:
init:
name: Initialize build
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- uses: actions/checkout@v3
- name: Get tag
id: tag
# yamllint disable rule:line-length
run: |
if [[ "$GITHUB_EVENT_NAME" = "release" ]]; then
TAG="${GITHUB_REF#refs/tags/}"
else
TAG=$(cat package.json | sed -n -E "s/\s*\"version\":\s*\"(.+)\",$/\1/p")
today="$(date --utc '+%Y%m%d')"
TAG="${TAG}-${today}"
BRANCH=${GITHUB_REF#refs/heads/}
if [[ "$BRANCH" != "dev" ]]; then
TAG="${TAG}-${BRANCH}"
fi
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
# yamllint enable rule:line-length

deploy-docker:
name: Build and publish Typedaemon # ${{ matrix.image.title}}
if: github.repository == 'matchlighter/typedaemon'
Expand All @@ -46,7 +30,6 @@ jobs:
packages: write
runs-on: ubuntu-latest
# continue-on-error: ${{ matrix.image.title == 'lint' }}
needs: [init]
strategy:
fail-fast: false
# matrix:
Expand Down Expand Up @@ -87,8 +70,7 @@ jobs:
- name: Generate short tags
id: tags
run: |
script/generate_tags.py \
--tag "${{ needs.init.outputs.tag }}"
script/generate_tags.py
# --suffix "${{ matrix.image.suffix }}"

- name: Build and push
Expand All @@ -106,25 +88,25 @@ jobs:
tags: ${{ steps.tags.outputs.tags }}
# BASEIMGTYPE=${{ matrix.image.baseimg }}
build-args: |
BUILD_VERSION=${{ needs.init.outputs.tag }}
BUILD_VERSION=${{ steps.tags.outputs.version }}
# deploy-ha-addon-repo:
# if: github.repository == 'matchlighter/typedaemon' && github.event_name == 'release'
# runs-on: ubuntu-latest
# needs: [deploy-docker]
# steps:
# - name: Trigger Workflow
# uses: actions/github-script@v6
# with:
# github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
# script: |
# github.rest.actions.createWorkflowDispatch({
# owner: "matchlighter",
# repo: "typedaemon-hassio",
# workflow_id: "bump-version.yml",
# ref: "main",
# inputs: {
# version: "${{ github.event.release.tag_name }}",
# content: ${{ toJSON(github.event.release.body) }}
# }
# })
deploy-ha-addon-repo:
if: github.repository == 'matchlighter/typedaemon' && github.event_name == 'release'
runs-on: ubuntu-latest
needs: [deploy-docker]
steps:
- name: Trigger Workflow
uses: actions/github-script@v6
with:
github-token: ${{ secrets.DEPLOY_HA_ADDON_REPO_TOKEN }}
script: |
github.rest.actions.createWorkflowDispatch({
owner: "matchlighter",
repo: "typedaemon-hassio",
workflow_id: "bump-version.yml",
ref: "main",
inputs: {
version: "${{ github.event.release.tag_name }}",
content: ${{ toJSON(github.event.release.body) }}
}
})
2 changes: 1 addition & 1 deletion docker/static_bin/build_socat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function build_openssl() {
cd openssl-${OPENSSL_VERSION}

# Configure
CC='/usr/bin/gcc -static' ./Configure no-shared no-async linux-x86_64
CC='/usr/bin/gcc -static' ./Configure no-shared no-async linux-$(uname -m)

# Build
make -j4
Expand Down
46 changes: 28 additions & 18 deletions script/generate_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
import re
import os
import argparse
import datetime
import json

CHANNEL_DEV = "dev"
CHANNEL_BETA = "beta"
CHANNEL_RELEASE = "release"

parser = argparse.ArgumentParser()
parser.add_argument(
"--tag",
type=str,
required=True,
help="The main docker tag to push to. If a version number also adds latest and/or beta tag",
)
parser.add_argument(
"--suffix",
type=str,
Expand All @@ -26,21 +21,35 @@
def main():
args = parser.parse_args()

# detect channel from tag
match = re.match(r"^(\d+\.\d+)(?:\.\d+)?(b\d+)?$", args.tag)
channel = CHANNEL_DEV
version = ""
major_minor_version = None
if match is None:
channel = CHANNEL_DEV
elif match.group(2) is None:
major_minor_version = match.group(1)
channel = CHANNEL_RELEASE
tags_to_push = []
if os.environ.get("GITHUB_EVENT_NAME", None) == "release":
version = os.environ.get("GITHUB_REF").replace("refs/tags/", "")
tags_to_push.append(version)

# detect channel from tag
match = re.match(r"^(\d+\.\d+)(?:\.\d+)?(b\d+)?$", version)
major_minor_version = None
if match is None:
channel = CHANNEL_DEV
elif match.group(2) is None:
major_minor_version = match.group(1)
channel = CHANNEL_RELEASE
else:
channel = CHANNEL_BETA
else:
channel = CHANNEL_BETA
branch = os.environ.get("GITHUB_REF", "arbitrary").replace("refs/heads/", "")
sha = os.environ.get("GITHUB_SHA", "")
datecode = datetime.datetime.now().isoformat()
version = f"{branch}-{sha}-{datecode}"
if branch == "master":
tags_to_push.append("edge")
else:
tags_to_push.append(f"branch-{branch}")

tags_to_push = [args.tag]
if channel == CHANNEL_DEV:
tags_to_push.append("dev")
elif channel == CHANNEL_BETA:
if channel == CHANNEL_BETA:
tags_to_push.append("beta")
elif channel == CHANNEL_RELEASE:
# Additionally push to beta
Expand All @@ -54,6 +63,7 @@ def main():
suffix = f"-{args.suffix}" if args.suffix else ""

with open(os.environ["GITHUB_OUTPUT"], "w") as f:
print(f"version={version}", file=f)
print(f"channel={channel}", file=f)
print(f"image=matchlighter/typedaemon{suffix}", file=f)
full_tags = []
Expand Down

0 comments on commit a727618

Please sign in to comment.