ci: port release workflow to Gitea Actions (tag + release zip, optional HACS GitHub mirror)
This commit is contained in:
1 parent
afc5f0a1d0
commit
37df5732b7
1 file changed
+107
-9
@@ -2,16 +2,23 @@ name: Release
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [master]
|
||||||
paths:
|
paths:
|
||||||
- custom_components/nvidia_shield/manifest.json
|
- custom_components/nvidia_shield/manifest.json
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
ZIP_NAME: nvidia_shield.zip
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
# 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
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
outputs:
|
||||||
|
tag: ${{ steps.version.outputs.tag }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@@ -36,16 +43,107 @@ jobs:
|
|||||||
- name: Create tag
|
- name: Create tag
|
||||||
if: steps.check.outputs.exists == 'false'
|
if: steps.check.outputs.exists == 'false'
|
||||||
run: |
|
run: |
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "release-bot"
|
||||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
git config user.email "release-bot@notexpectedyet.com"
|
||||||
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
|
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
|
||||||
git push origin "${{ steps.version.outputs.tag }}"
|
git push origin "${{ steps.version.outputs.tag }}"
|
||||||
|
|
||||||
- name: Create GitHub Release
|
- 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'
|
if: steps.check.outputs.exists == 'false'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
TAG: ${{ steps.version.outputs.tag }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
run: |
|
run: |
|
||||||
gh release create "${{ steps.version.outputs.tag }}" \
|
API_URL="${GITHUB_API_URL:-$(echo "$GITHUB_SERVER_URL" | sed 's#/$##')/api/v1}"
|
||||||
--title "${{ steps.version.outputs.tag }}" \
|
echo "API: $API_URL, repo: $REPO, tag: $TAG"
|
||||||
--generate-notes
|
|
||||||
|
# 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"
|
||||||
Reference in new issue
Block a user