-
Notifications
You must be signed in to change notification settings - Fork 11
101 lines (80 loc) · 3.16 KB
/
Copy pathrelease.yml
File metadata and controls
101 lines (80 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Release workflow
#
# When a semver tag (v0.1.0) is pushed:
# 1. Creates a GitHub release with auto-generated notes
# 2. Updates the major version tag (v0) to point to this release
#
# Usage:
# git tag v0.1.0
# git push origin v0.1.0
#
# This allows users to reference either:
# - elastic/ai-github-actions/...@v0 (latest v0.x.x)
# - elastic/ai-github-actions/...@v0.1.0 (exact version)
name: "Internal: Release"
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # Matches v1.0.0, v2.1.3, etc.
permissions:
contents: write
# Serialize all release runs to prevent race conditions when force-updating major version tags.
# Without this, concurrent releases could race on updating the same floating major tag (e.g., v0).
# cancel-in-progress: false ensures each release completes rather than being cancelled.
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Extract version info
id: version
run: |
# Get the tag name (e.g., v1.2.3)
TAG="${GITHUB_REF#refs/tags/}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
# Extract major version (e.g., v1)
MAJOR=$(echo "$TAG" | grep -oE '^v[0-9]+')
echo "major=$MAJOR" >> "$GITHUB_OUTPUT"
# Get the full commit SHA
SHA="${GITHUB_SHA}"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
echo "Creating release for $TAG (major: $MAJOR, sha: $SHA)"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${{ steps.version.outputs.tag }}"
MAJOR="${{ steps.version.outputs.major }}"
SHA="${{ steps.version.outputs.sha }}"
# Create release notes header with SHA for pinning
NOTES_HEADER="## Installation
\`\`\`yaml
# Use floating major version (recommended)
- uses: elastic/ai-github-actions/...@${MAJOR}
# Pin to this exact release
- uses: elastic/ai-github-actions/...@${TAG}
# Pin to commit SHA (maximum security)
- uses: elastic/ai-github-actions/...@${SHA}
\`\`\`
---
"
gh release create "$TAG" \
--title "$TAG" \
--notes "${NOTES_HEADER}$(gh api repos/${{ github.repository }}/releases/generate-notes -f tag_name="$TAG" --jq '.body')"
- name: Update major version tag
run: |
MAJOR="${{ steps.version.outputs.major }}"
TAG="${{ steps.version.outputs.tag }}"
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Force-update the major version tag to point to the same commit as the semver tag
# The -f flag allows overwriting an existing tag
# The -a flag creates an annotated tag with a message
git tag -fa "$MAJOR" "$TAG" -m "Release $TAG"
git push origin "$MAJOR" --force
echo "Updated $MAJOR to point to $TAG"