name: Create Release on: workflow_call: inputs: tag: description: 'Full commit SHA for tagging' required: true type: string branch: description: 'Branch name used as release tag suffix (e.g. canary_experimental)' default: 'canary_experimental' type: string jobs: release: runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout repository for git log access uses: actions/checkout@v6 with: fetch-depth: 0 - name: Build release notes id: notes env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} run: |- FULL_SHA="${{ inputs.tag }}" SHORT_SHA="${FULL_SHA::7}" BRANCH="${{ inputs.branch }}" TAG_NAME="$SHORT_SHA" TITLE="${SHORT_SHA}_$BRANCH" echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT echo "title=$TITLE" >> $GITHUB_OUTPUT PREV_TAG=$(gh release list \ --repo "$REPO" \ --limit 1 \ --json tagName \ --jq '.[0].tagName' 2>/dev/null || echo) if [ -n "$PREV_TAG" ]; then PREV_SHA=$(git rev-parse "${PREV_TAG}^{}" 2>/dev/null || \ git rev-parse "${PREV_TAG}" 2>/dev/null || echo) fi if [ -n "$PREV_SHA" ]; then COMMITS=$(git log --format='- %s (`%h`)' --abbrev=7 "${PREV_SHA}..$FULL_SHA" --) COMPARE_URL="https://github.com/${REPO}/compare/${PREV_TAG}...$TAG_NAME" else COMMITS=$(git log --format='- %s (`%h`)' --abbrev=7 -1 "$FULL_SHA" --) fi # Assemble body { echo "body<> $GITHUB_OUTPUT - name: Download artifacts uses: actions/download-artifact@v8 with: path: release_assets merge-multiple: true - name: Create GitHub Release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} TAG: ${{ steps.notes.outputs.tag_name }} TITLE: ${{ steps.notes.outputs.title }} BODY: ${{ steps.notes.outputs.body }} TARGET: ${{ inputs.tag }} run: |- echo "$BODY" > release_notes.md echo "Creating release: $TAG" # Check if tag/release already exists (re-run safety) if gh release view "$TAG" --repo "$REPO" --json tagName 2>/dev/null; then echo "Release $TAG exists, uploading new assets..." gh release upload "$TAG" \ --repo "$REPO" \ --clobber \ release_assets/* else gh release create "$TAG" \ --repo "$REPO" \ --target "${{ inputs.tag }}" \ --title "$TITLE" \ --notes-file release_notes.md \ --latest \ release_assets/* fi echo "✅ Release $TAG published"