-
Notifications
You must be signed in to change notification settings - Fork 1
174 lines (157 loc) · 5.34 KB
/
release.yml
File metadata and controls
174 lines (157 loc) · 5.34 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
163
164
165
166
167
168
169
170
171
172
173
174
name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Tag to release (e.g., v0.1.0)"
required: true
dry_run:
description: "Dry run (skip release creation)"
type: boolean
default: true
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
extract-version:
name: Extract Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
ref: ${{ steps.version.outputs.ref }}
steps:
- name: Determine tag
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="${{ inputs.tag }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Invalid tag format: '$TAG'. Expected format like v0.1.0 or v0.1.0-rc.1"
exit 1
fi
REF="refs/tags/${TAG}"
else
TAG="${GITHUB_REF#refs/tags/}"
REF="${GITHUB_REF}"
fi
VERSION="${TAG#v}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "ref=$REF" >> "$GITHUB_OUTPUT"
echo "Extracted version: $VERSION"
check-version:
name: Check Version
runs-on: ubuntu-latest
needs: extract-version
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ needs.extract-version.outputs.ref }}
persist-credentials: false
- name: Verify Cargo.toml version matches tag
run: |
CARGO_VERSION=$(cargo metadata --format-version 1 --no-deps \
| jq -r '.packages[] | select(.name == "morph-reth") | .version')
TAG_VERSION="${{ needs.extract-version.outputs.version }}"
echo "Cargo.toml version: $CARGO_VERSION"
echo "Tag version: $TAG_VERSION"
if [[ "$TAG_VERSION" != "$CARGO_VERSION"* ]]; then
echo "::error::Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
build:
name: Build ${{ matrix.target }}
runs-on: ubuntu-latest
needs: [extract-version, check-version]
if: ${{ !cancelled() && needs.check-version.result == 'success' }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
archive: morph-reth-${{ needs.extract-version.outputs.version }}-x86_64-linux
- target: aarch64-unknown-linux-gnu
archive: morph-reth-${{ needs.extract-version.outputs.version }}-aarch64-linux
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ needs.extract-version.outputs.ref }}
persist-credentials: false
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Rust build artifacts
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
key: ${{ matrix.target }}
- name: Install cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Build binary
run: cross build --release --locked --target ${{ matrix.target }} --bin morph-reth
- name: Package binary
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/morph-reth dist/
cd dist
tar czf ../${{ matrix.archive }}.tar.gz morph-reth
cd ..
sha256sum ${{ matrix.archive }}.tar.gz > ${{ matrix.archive }}.tar.gz.sha256
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.archive }}
path: |
${{ matrix.archive }}.tar.gz
${{ matrix.archive }}.tar.gz.sha256
draft-release:
name: Draft Release
runs-on: ubuntu-latest
needs: [extract-version, build]
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.dry_run) }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ needs.extract-version.outputs.ref }}
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: artifacts
- name: Generate changelog
id: changelog
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [[ -n "$PREVIOUS_TAG" ]]; then
CHANGELOG=$(git log --pretty=format:"- %s" ${PREVIOUS_TAG}..HEAD)
else
CHANGELOG=$(git log -n 20 --pretty=format:"- %s")
fi
# Write to file to avoid escaping issues
echo "$CHANGELOG" > changelog.md
- name: Create draft release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ needs.extract-version.outputs.version }}"
PRERELEASE=""
if [[ "$VERSION" == *"alpha"* ]] || [[ "$VERSION" == *"beta"* ]] || [[ "$VERSION" == *"rc"* ]]; then
PRERELEASE="--prerelease"
fi
gh release create "v${VERSION}" \
--verify-tag \
--draft \
--title "v${VERSION}" \
--notes-file changelog.md \
$PRERELEASE \
artifacts/*