-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (138 loc) · 6.2 KB
/
release-recipe.yml
File metadata and controls
162 lines (138 loc) · 6.2 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Release Recipe
on:
push:
tags:
- "rust-v*"
- "rust-latest"
- "motoko-v*"
- "motoko-latest"
- "asset-canister-v*"
- "asset-canister-latest"
- "prebuilt-v*"
- "prebuilt-latest"
permissions:
contents: write
jobs:
release-recipe:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0 # Fetch all history and tags
- name: Extract recipe and version from tag
id: tag_info
run: |
TAG=${GITHUB_REF#refs/tags/}
RECIPE=$(echo "$TAG" | sed 's/-[^-]*$//')
VERSION=$(echo "$TAG" | sed 's/^.*-//')
# Handle latest tags specially
if [ "$VERSION" = "latest" ]; then
echo "recipe=$RECIPE" >> "$GITHUB_OUTPUT"
echo "version=latest" >> "$GITHUB_OUTPUT"
echo "is_latest=true" >> "$GITHUB_OUTPUT"
else
echo "recipe=$RECIPE" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "is_latest=false" >> "$GITHUB_OUTPUT"
fi
- name: Package Recipe
run: |
mkdir -p release
# Copy individual recipe files
cp recipes/${{ steps.tag_info.outputs.recipe }}/recipe.hbs release/
# Create archives
tar -czf release/${{ steps.tag_info.outputs.recipe }}-${{ steps.tag_info.outputs.version }}.tar.gz recipes/${{ steps.tag_info.outputs.recipe }}/
zip -r release/${{ steps.tag_info.outputs.recipe }}-${{ steps.tag_info.outputs.version }}.zip recipes/${{ steps.tag_info.outputs.recipe }}/
- name: Generate Checksums
run: |
cd release
sha256sum * > checksums.txt
- name: Find previous recipe version
id: prev_version
run: |
RECIPE="${{ steps.tag_info.outputs.recipe }}"
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
IS_LATEST="${{ steps.tag_info.outputs.is_latest }}"
if [ "$IS_LATEST" = "true" ]; then
# For -latest tags: find the versioned tag pointing to the same commit
CURRENT_COMMIT=$(git rev-parse HEAD)
CURRENT_VERSION_TAG=$(git tag --sort=-version:refname -l "${RECIPE}-v*" | while read -r tag; do
if [ "$(git rev-parse "$tag")" = "$CURRENT_COMMIT" ]; then
echo "$tag"
break
fi
done)
if [ -z "$CURRENT_VERSION_TAG" ]; then
echo "::error::No versioned tag found for this commit. A -latest tag must have a corresponding versioned tag (e.g., ${RECIPE}-v1.0.0) on the same commit."
exit 1
else
echo "Found versioned tag for this commit: ${CURRENT_VERSION_TAG}"
# Find the previous version before the current versioned tag
PREV_TAG=$(git tag --sort=-version:refname -l "${RECIPE}-v*" | grep -v "${CURRENT_VERSION_TAG}" | head -n 1)
echo "previous_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT"
echo "compare_tag=${CURRENT_VERSION_TAG}" >> "$GITHUB_OUTPUT"
fi
else
# For versioned tags: find the previous version tag
PREV_TAG=$(git tag --sort=-version:refname -l "${RECIPE}-v*" | grep -v "${CURRENT_TAG}" | head -n 1)
if [ -z "$PREV_TAG" ]; then
echo "No previous version found for ${RECIPE}"
echo "previous_tag=" >> "$GITHUB_OUTPUT"
else
echo "Found previous tag: ${PREV_TAG}"
echo "previous_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT"
fi
echo "compare_tag=${CURRENT_TAG}" >> "$GITHUB_OUTPUT"
fi
- name: Generate Release Notes Body
id: release_notes
run: |
RECIPE="${{ steps.tag_info.outputs.recipe }}"
PREV_TAG="${{ steps.prev_version.outputs.previous_tag }}"
COMPARE_TAG="${{ steps.prev_version.outputs.compare_tag }}"
if [ -n "$PREV_TAG" ] && [ -n "$COMPARE_TAG" ]; then
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
# Get commits that affect this recipe's directory
COMMITS=$(git log ${PREV_TAG}..${COMPARE_TAG} --pretty=format:"* %s (%h)" --no-merges -- recipes/${RECIPE}/)
if [ -n "$COMMITS" ]; then
echo "Changes since ${PREV_TAG}:" >> release_notes.md
echo "" >> release_notes.md
echo "$COMMITS" >> release_notes.md
echo "" >> release_notes.md
else
echo "No changes to the ${RECIPE} recipe files." >> release_notes.md
echo "" >> release_notes.md
fi
echo "" >> release_notes.md
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${COMPARE_TAG}" >> release_notes.md
else
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
echo "Initial release of the ${RECIPE} recipe." >> release_notes.md
fi
- name: Create Release
uses: softprops/action-gh-release@aec2ec56f94eb8180ceec724245f64ef008b89f5 # v2.4.0
with:
tag_name: ${{ steps.tag_info.outputs.recipe }}-${{ steps.tag_info.outputs.version }}
name: ${{ steps.tag_info.outputs.recipe }} ${{ steps.tag_info.outputs.version }}
files: release/*
body_path: release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update latest tag
if: steps.tag_info.outputs.is_latest == 'false'
run: |
RECIPE="${{ steps.tag_info.outputs.recipe }}"
CURRENT_TAG="${GITHUB_REF#refs/tags/}"
echo "Updating ${RECIPE}-latest to point to ${CURRENT_TAG}"
# Delete the old latest tag locally and remotely
git tag -d ${RECIPE}-latest 2>/dev/null || true
git push origin :refs/tags/${RECIPE}-latest 2>/dev/null || true
# Create new latest tag pointing to current commit
git tag ${RECIPE}-latest
# Push the new latest tag
git push origin ${RECIPE}-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}