159 lines
6.1 KiB
YAML
159 lines
6.1 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
ZIP_NAME: nvidia_shield.zip
|
|
|
|
jobs:
|
|
# Tag + release on Gitea (https://git.notexpectedyet.com/notexpectedyet/ha-nvidia-shield).
|
|
# Always runs; this is the source-of-truth release.
|
|
gitea-release:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
outputs:
|
|
tag: ${{ steps.version.outputs.tag }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# Date-based versioning: vYYYY.MM.DD.
|
|
# Priority: an unreleased manifest version wins (bump manifest.json to
|
|
# force a specific version); otherwise fall back to today's date, so a
|
|
# plain push to master produces/updates the day's release. The
|
|
# tag-exists check below dedupes same-day pushes.
|
|
- name: Determine release version
|
|
id: version
|
|
run: |
|
|
MANIFEST_VERSION=$(jq -r .version custom_components/nvidia_shield/manifest.json)
|
|
DATE_VERSION=$(date -u +%Y.%m.%d)
|
|
if git ls-remote --tags origin "refs/tags/v$MANIFEST_VERSION" | grep -q .; then
|
|
VERSION="$DATE_VERSION"
|
|
else
|
|
VERSION="$MANIFEST_VERSION"
|
|
fi
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Check if tag already exists
|
|
id: check
|
|
run: |
|
|
if git ls-remote --tags origin "refs/tags/${{ steps.version.outputs.tag }}" | grep -q .; then
|
|
echo "exists=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "exists=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Create tag
|
|
if: steps.check.outputs.exists == 'false'
|
|
run: |
|
|
git config user.name "release-bot"
|
|
git config user.email "release-bot@notexpectedyet.com"
|
|
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
|
|
git push origin "${{ steps.version.outputs.tag }}"
|
|
|
|
- name: Build release zip
|
|
if: steps.check.outputs.exists == 'false'
|
|
run: |
|
|
cd custom_components
|
|
zip -r "../${ZIP_NAME}" nvidia_shield
|
|
|
|
# Gitea Actions sets GITHUB_API_URL (https://<host>/api/v1) and
|
|
# GITHUB_TOKEN for compatibility; no secrets needed for the Gitea release.
|
|
- name: Create Gitea release and upload zip
|
|
if: steps.check.outputs.exists == 'false'
|
|
env:
|
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
TAG: ${{ steps.version.outputs.tag }}
|
|
REPO: ${{ github.repository }}
|
|
run: |
|
|
API_URL="${GITHUB_API_URL:-$(echo "$GITHUB_SERVER_URL" | sed 's#/$##')/api/v1}"
|
|
echo "API: $API_URL, repo: $REPO, tag: $TAG"
|
|
|
|
# Release notes: subjects of commits since the previous tag
|
|
PREV=$(git describe --tags --abbrev=0 "$TAG^" 2>/dev/null || true)
|
|
if [ -n "$PREV" ]; then
|
|
RANGE="$PREV..$TAG"
|
|
else
|
|
RANGE="$TAG"
|
|
fi
|
|
NOTES=$(git log --pretty=format:'- %s' "$RANGE" | head -30)
|
|
PAYLOAD=$(jq -n --arg tag "$TAG" --arg body "$NOTES" \
|
|
'{tag_name:$tag, name:$tag, body:$body, draft:false, prerelease:false}')
|
|
|
|
# Create the release; if one already exists for this tag, reuse it
|
|
CREATE_RESP=$(curl -s -X POST "$API_URL/repos/$REPO/releases" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$PAYLOAD")
|
|
RELEASE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty')
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Release create returned no id (already exists?) — looking up by tag"
|
|
RELEASE_ID=$(curl -s "$API_URL/repos/$REPO/releases/tags/$TAG" \
|
|
-H "Authorization: token $TOKEN" | jq -r '.id')
|
|
fi
|
|
echo "Release id: $RELEASE_ID"
|
|
|
|
curl -s -f -X POST "$API_URL/repos/$REPO/releases/$RELEASE_ID/assets?name=$ZIP_NAME" \
|
|
-H "Authorization: token $TOKEN" \
|
|
-F "attachment=@${ZIP_NAME}" > /dev/null
|
|
echo "Uploaded $ZIP_NAME to $TAG"
|
|
|
|
# Optional: mirror the release to a public GitHub repository so HACS can
|
|
# distribute it (HACS only supports public GitHub repos).
|
|
# Required secrets:
|
|
# GH_MIRROR_TOKEN — GitHub PAT with repo (contents) scope
|
|
# GH_MIRROR_REPO — target repo, e.g. "notexpectedyet/ha-nvidia-shield"
|
|
hacs-github-mirror:
|
|
runs-on: ubuntu-latest
|
|
needs: gitea-release
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Push mirror and create GitHub release
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GH_MIRROR_TOKEN }}
|
|
GH_REPO: ${{ secrets.GH_MIRROR_REPO }}
|
|
TAG: ${{ needs.gitea-release.outputs.tag }}
|
|
run: |
|
|
if [ -z "$GH_TOKEN" ] || [ -z "$GH_REPO" ]; then
|
|
echo "GH_MIRROR_TOKEN / GH_MIRROR_REPO not set — skipping GitHub mirror."
|
|
exit 0
|
|
fi
|
|
|
|
git remote add github "https://x-access-token:${GH_TOKEN}@github.com/${GH_REPO}.git"
|
|
git push github HEAD:master
|
|
|
|
if git push github "refs/tags/$TAG" 2>/dev/null; then
|
|
echo "Pushed tag $TAG to GitHub"
|
|
else
|
|
echo "Tag $TAG already exists on GitHub"
|
|
fi
|
|
|
|
RESP=$(curl -s -X POST "https://api.github.com/repos/${GH_REPO}/releases" \
|
|
-H "Authorization: Bearer $GH_TOKEN" \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"Release $TAG\",\"draft\":false,\"prerelease\":false}")
|
|
RELEASE_ID=$(echo "$RESP" | jq -r '.id // empty')
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "GitHub release create failed or already exists:"
|
|
echo "$RESP"
|
|
exit 0
|
|
fi
|
|
|
|
cd custom_components
|
|
zip -r "../${ZIP_NAME}" nvidia_shield
|
|
cd ..
|
|
|
|
curl -s -f -X POST "https://uploads.github.com/repos/${GH_REPO}/releases/${RELEASE_ID}/assets?name=$ZIP_NAME" \
|
|
-H "Authorization: Bearer $GH_TOKEN" \
|
|
-F "attachment=@${ZIP_NAME}" > /dev/null
|
|
echo "Uploaded $ZIP_NAME to GitHub release $TAG"
|