-
Notifications
You must be signed in to change notification settings - Fork 1.2k
121 lines (102 loc) · 3.94 KB
/
Copy pathcreate-draft-release.yml
File metadata and controls
121 lines (102 loc) · 3.94 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Create Draft Release
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: write
jobs:
create-draft-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for all tags
- name: Extract changelog for version
id: changelog
run: |
VERSION="${GITHUB_REF#refs/tags/}"
echo "Creating release for version: $VERSION"
# Extract changelog section for this version
# This awk script extracts content between ## VERSION and the next ## line
CHANGELOG=$(awk -v version="$VERSION" '
/^## / {
if (found) exit;
if ($2 == version) found=1;
next;
}
found { print }
' CHANGELOG.md)
if [ -z "$CHANGELOG" ]; then
echo "No changelog entry found for version $VERSION"
exit 1
fi
# Save changelog to file (multiline output)
echo "$CHANGELOG" > /tmp/changelog.txt
echo "changelog_file=/tmp/changelog.txt" >> $GITHUB_OUTPUT
- name: Get previous tag
id: prev_tag
run: |
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
# Get all tags sorted by version, find the one before current
PREV_TAG=$(git tag --sort=-version:refname | grep -A1 "^${CURRENT_TAG}$" | tail -n1)
if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" = "$CURRENT_TAG" ]; then
echo "No previous tag found"
echo "has_prev_tag=false" >> $GITHUB_OUTPUT
else
echo "Previous tag: $PREV_TAG"
echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
echo "has_prev_tag=true" >> $GITHUB_OUTPUT
fi
- name: Create release body
id: release_body
run: |
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
CHANGELOG=$(cat /tmp/changelog.txt)
# Start building the release body
{
echo "$CHANGELOG"
echo ""
# Add diff link if we have a previous tag
if [ "${{ steps.prev_tag.outputs.has_prev_tag }}" = "true" ]; then
PREV_TAG="${{ steps.prev_tag.outputs.prev_tag }}"
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${CURRENT_TAG}"
fi
} > /tmp/release_body.txt
echo "release_body_file=/tmp/release_body.txt" >> $GITHUB_OUTPUT
- name: Create draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
RELEASE_BODY=$(cat /tmp/release_body.txt)
gh release create "$CURRENT_TAG" \
--draft \
--title "$CURRENT_TAG" \
--notes "$RELEASE_BODY"
echo "✅ Draft release created for $CURRENT_TAG"
load-failure-secrets:
if: failure()
needs: create-draft-release
runs-on: ubuntu-latest
outputs:
slack-webhook-url: ${{ steps.load-secrets.outputs.SLACK_WEBHOOK_URL }}
steps:
- name: Load secrets
uses: 1password/load-secrets-action@8d0d610af187e78a2772c2d18d627f4c52d3fbfb # v3.1.0
id: load-secrets
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
SLACK_WEBHOOK_URL: "op://Continuous Integration/DASHBOARD_BUILD_FAILURE_SLACK_WEBHOOK/password"
notify-failure:
if: failure()
needs: [create-draft-release, load-failure-secrets]
permissions: {}
uses: saleor/saleor-internal-actions/.github/workflows/notify-slack.yaml@eb0c692da7bf13f5e1a82c17488b24c514dd10a1 # v1.10.0
with:
custom_title: "🚨 Draft Release Creation Failed for *${{ github.ref_name }}*"
status: failure
secrets:
mention_group_id: ${{ secrets.SLACK_DASHBOARD_GROUP_ID }}
slack-webhook-url: ${{ needs.load-failure-secrets.outputs.slack-webhook-url }}