[codex] optimize release action chain #80
This file contains hidden or 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: 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 | |
| branches: | |
| - develop | |
| jobs: | |
| dispatch_develop_synced: | |
| 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: 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 | |
| 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 | |
| if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Invalid develop-synced version: ${VERSION}" | |
| exit 1 | |
| fi | |
| echo "Parsed version: ${VERSION}" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| - name: Send repository_dispatch develop-synced | |
| if: steps.version.outputs.version != '' | |
| env: | |
| GH_TOKEN: ${{ secrets.CREATE_TAG_RELEASE_TOKEN || github.token }} | |
| run: | | |
| set -euo pipefail | |
| VERSION="${{ steps.version.outputs.version }}" | |
| OWNER_REPO="${GITHUB_REPOSITORY}" | |
| PAYLOAD="$(VERSION="${VERSION}" node -e ' | |
| const version = process.env.VERSION; | |
| process.stdout.write(JSON.stringify({ | |
| event_type: "develop-synced", | |
| client_payload: { version } | |
| })); | |
| ')" | |
| echo "Sending repository_dispatch develop-synced for version ${VERSION} to ${OWNER_REPO}" | |
| curl --fail-with-body -sS -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${GH_TOKEN}" \ | |
| "https://api.github.com/repos/${OWNER_REPO}/dispatches" \ | |
| -d "${PAYLOAD}" |