Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .github/workflows/develop-synced-dispatch.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Dispatch develop-synced after sync/main merged (Scheme A)

on:
workflow_dispatch:
inputs:
version:
description: 'Release version, e.g. 1.2.3'
required: true
type: string
pull_request:
types:
- closed
Expand All @@ -9,42 +15,50 @@ on:

jobs:
dispatch_develop_synced:
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'sync/main-')
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'sync/main-'))

runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Derive version from sync branch
- name: Resolve version from input or sync branch
id: version
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
set -euo pipefail
BRANCH="${{ github.event.pull_request.head.ref }}"
echo "Head branch: ${BRANCH}"
VERSION="${BRANCH#sync/main-}"
if [ -z "${VERSION}" ] || [ "${VERSION}" = "${BRANCH}" ]; then
echo "Failed to parse version from branch ${BRANCH}, skip dispatch."
echo "version=" >> "$GITHUB_OUTPUT"
exit 0
VERSION="${INPUT_VERSION:-}"
if [ -z "${VERSION}" ]; then
BRANCH="${PR_HEAD_REF}"
echo "Head branch: ${BRANCH}"
VERSION="${BRANCH#sync/main-}"
if [ -z "${VERSION}" ] || [ "${VERSION}" = "${BRANCH}" ]; then
echo "Failed to parse version from branch ${BRANCH}, skip dispatch."
echo "version=" >> "$GITHUB_OUTPUT"
exit 0
fi
fi
echo "Parsed version: ${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"

- name: Send repository_dispatch develop-synced
if: steps.version.outputs.version != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
run: |
set -euo pipefail
VERSION="${{ steps.version.outputs.version }}"
OWNER_REPO="${GITHUB_REPOSITORY}"

echo "Sending repository_dispatch develop-synced for version ${VERSION} to ${OWNER_REPO}"

curl -X POST \
curl --fail-with-body -sS -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Authorization: Bearer ${GH_TOKEN}" \
"https://api.github.com/repos/${OWNER_REPO}/dispatches" \
-d "{\"event_type\":\"develop-synced\",\"client_payload\":{\"version\":\"${VERSION}\"}}"
63 changes: 38 additions & 25 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Post release after develop synced

on:
repository_dispatch:
types: [develop-synced]
workflow_dispatch:
inputs:
version:
Expand All @@ -16,19 +18,21 @@ jobs:
contents: write

steps:
- name: Read version from workflow_dispatch input
- name: Read version from event payload or workflow_dispatch input
id: meta
env:
PAYLOAD_VERSION: ${{ github.event.client_payload.version }}
INPUT_VERSION: ${{ github.event.inputs.version }}
run: |
set -euo pipefail
if [ -z "${INPUT_VERSION}" ]; then
echo "No version in workflow_dispatch input, skip post-release."
VERSION="${PAYLOAD_VERSION:-${INPUT_VERSION:-}}"
if [ -z "${VERSION}" ]; then
echo "No version in repository_dispatch payload or workflow_dispatch input, skip post-release."
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Using version from input: ${INPUT_VERSION}"
echo "version=${INPUT_VERSION}" >> "$GITHUB_OUTPUT"
echo "Using version: ${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"

- name: Checkout main
Expand All @@ -39,14 +43,13 @@ jobs:
fetch-depth: 0
persist-credentials: false

- name: Configure git remote to use PAT
- name: Configure git remote for tag push
if: steps.meta.outputs.skip != 'true'
env:
GH_PAT: ${{ secrets.CREATE_TAG_RELEASE_TOKEN }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
run: |
set -euo pipefail
git remote set-url origin "https://x-access-token:${GH_PAT}@github.com/${GITHUB_REPOSITORY}.git"
git remote -v
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

- name: Fetch tags
if: steps.meta.outputs.skip != 'true'
Expand All @@ -59,24 +62,29 @@ jobs:
if: steps.meta.outputs.skip != 'true'
env:
VERSION: ${{ steps.meta.outputs.version }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
run: |
set -euo pipefail
TAG="v${VERSION}"
TAG_EXISTS="false"
RELEASE_EXISTS="false"

if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "Tag ${TAG} already exists, skip post-release."
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
echo "Tag ${TAG} already exists."
TAG_EXISTS="true"
fi

if gh release view "${TAG}" >/dev/null 2>&1; then
echo "Release ${TAG} already exists, skip post-release."
RELEASE_EXISTS="true"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
else
echo "Release ${TAG} does not exist, continue post-release."
echo "skip=false" >> "$GITHUB_OUTPUT"
fi

echo "skip=false" >> "$GITHUB_OUTPUT"
echo "tag_exists=${TAG_EXISTS}" >> "$GITHUB_OUTPUT"
echo "release_exists=${RELEASE_EXISTS}" >> "$GITHUB_OUTPUT"

- name: Ensure main changelog exists
if: steps.meta.outputs.skip != 'true' && steps.exist.outputs.skip != 'true'
Expand Down Expand Up @@ -161,15 +169,15 @@ jobs:
- name: Verify gh identity
if: steps.meta.outputs.skip != 'true' && steps.exist.outputs.skip != 'true' && steps.body.outputs.has_body == 'true'
env:
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
run: |
set -euo pipefail
gh api user -q '.login'

- name: Diagnose PAT repository permission
- name: Diagnose repository token permission
if: steps.meta.outputs.skip != 'true' && steps.exist.outputs.skip != 'true' && steps.body.outputs.has_body == 'true'
env:
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
run: |
set -euo pipefail
LOGIN=$(gh api user -q '.login')
Expand All @@ -188,21 +196,26 @@ jobs:
echo "permission insufficient: $RESP"
fi

- name: Create tag and GitHub Release
- name: Create missing tag and GitHub Release
if: steps.meta.outputs.skip != 'true' && steps.exist.outputs.skip != 'true' && steps.body.outputs.has_body == 'true'
env:
VERSION: ${{ steps.meta.outputs.version }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN }}
GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }}
TAG_EXISTS: ${{ steps.exist.outputs.tag_exists }}
run: |
set -euo pipefail
TAG="v${VERSION}"

git fetch origin main:refs/remotes/origin/main --depth=1
MAIN_SHA="$(git rev-parse origin/main)"
if [ "${TAG_EXISTS}" != "true" ]; then
git fetch origin main:refs/remotes/origin/main --depth=1
MAIN_SHA="$(git rev-parse origin/main)"

echo "Creating tag ${TAG} at ${MAIN_SHA}"
git tag "${TAG}" "${MAIN_SHA}"
git push origin "${TAG}"
echo "Creating tag ${TAG} at ${MAIN_SHA}"
git tag "${TAG}" "${MAIN_SHA}"
git push origin "${TAG}"
else
echo "Using existing tag ${TAG}."
fi

echo "Creating GitHub Release ${TAG}"
gh release create "${TAG}" \
Expand Down
Loading
Loading