forked from Lightprotocol/light-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (145 loc) · 6.67 KB
/
release.yml
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
name: Release
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup and build
uses: ./.github/actions/setup-and-build
- name: Install cargo-workspaces
run: |
source ./scripts/devenv.sh
cargo install cargo-release cargo-workspaces
- name: Extract project
id: extract-project
shell: bash
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s' | sed 's/([^()]*)//g' | head -n 1)
PACKAGE=""
LANGUAGE=""
echo "Commit message: $COMMIT_MESSAGE"
if [[ "$COMMIT_MESSAGE" == "chore: Bump version of all Rust projects" ]]; then
PACKAGE="all"
LANGUAGE="rust"
elif [[ "$COMMIT_MESSAGE" == *"Bump version of all TypeScript"* ]]; then
PACKAGE="all"
LANGUAGE="ts"
elif [[ "$COMMIT_MESSAGE" == "chore: Bump version of Rust project "* ]]; then
PACKAGE=$(echo "$COMMIT_MESSAGE" | sed -n 's/chore: Bump version of Rust project \(.*\)/\1/p')
LANGUAGE="rust"
elif [[ "$COMMIT_MESSAGE" == *"Bump version of TypeScript project"* ]]; then
PACKAGE=$(echo "$COMMIT_MESSAGE" | grep -o "version of TypeScript project [^ ]*" | cut -d " " -f5)
LANGUAGE="rust"
fi
# Needed for Anchor.
PACKAGE_SNAKE_CASE=$(echo "$PACKAGE" | tr '-' '_')
printf "package=%s\package-snake-case=%s\nlanguage=%s\n" "$PACKAGE" "$PACKAGE_SNAKE_CASE" "$LANGUAGE" >> "$GITHUB_OUTPUT"
- name: Set Git user configuration
if: steps.extract-project.outputs.language != ''
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
- name: Tag all Rust projects
if: steps.extract-project.outputs.package == 'all' && steps.extract-project.outputs.language == 'rust'
run: |
for PACKAGE in $(cargo ws list); do
VERSION=$(cargo pkgid -p "$PACKAGE" | cut -d "@" -f2)
echo "Creating tag for Rust package: $PACKAGE v$VERSION"
git tag "${PACKAGE}-v${VERSION}"
git push origin "${PACKAGE}-v${VERSION}"
done
- name: Tag all TypeScript projects
if: steps.extract-project.outputs.package == 'all' && steps.extract-project.outputs.language == 'ts'
run: |
for dir in $(pnpm m ls --depth -1 --porcelain | grep -v examples | grep -v tsconfig | tail -n+2); do
pushd "$dir"
PACKAGE=$(basename "$dir")
VERSION=$(pnpm list --depth 0 --json | jq -r '.[0].version')
echo "Creating tag for TypeScript package: $PACKAGE v$VERSION"
git tag "${PACKAGE}-v${VERSION}"
git push origin "${PACKAGE}-v${VERSION}"
popd
done
- name: Tag Rust project
id: tag-rust
if: steps.extract-project.outputs.package != 'all' && steps.extract-project.outputs.language == 'rust'
env:
PACKAGE: ${{ steps.extract-project.outputs.version }}
run: |
VERSION=$(cargo pkgid -p "$PACKAGE" | cut -d "@" -f2)
echo "Creating tag for package: $PACKAGE v$VERSION"
git tag "${PACKAGE}-v${VERSION}"
git push origin "${PACKAGE}-v${VERSION}"
- name: Tag TypeScript project
id: tag-ts
if: steps.extract-project.outputs.package != 'all' && steps.extract-project.outputs.language == 'ts'
env:
PACKAGE: ${{ steps.extract-project.outputs.version }}
run: |
VERSION=$(pnpm list --filter "$1" --depth 0 --json | jq -r '.[0].version')
echo "Creating tag for package: $PACKAGE v$VERSION"
git tag "${PACKAGE}-v${VERSION}"
git push origin "${PACKAGE}-v${VERSION}"
- name: Log in to crates.io
if: steps.extract-project.outputs.language == 'rust'
run: |
cargo login "${{ secrets.CRATES_IO_TOKEN }}"
- name: Release all Rust projects
if: steps.extract-project.outputs.package == 'all' && steps.extract-project.outputs.language == 'rust'
shell: bash
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
PACKAGE: ${{ steps.extract-project.outputs.package }}
run: |
source ./scripts/devenv.sh
anchor build
cp -r ./target/deploy/*.so .
PACKAGES=("aligned-sized" "light-heap" "light-utils" "light-bounded-vec" "light-hasher" "light-macros" "light-hash-set" "light-merkle-tree-reference" "light-concurrent-merkle-tree" "light-indexed-merkle-tree" "light-prover-client" "light-verifier" "account-compression" "light-registry" "light-system-program" "light-compressed-token" "light-test-utils")
for PACKAGE in "${PACKAGES[@]}"; do
for attempt in {1..3}; do
echo "Attempt $attempt: Publishing $PACKAGE..."
cargo release publish --package "$PACKAGE" --execute --no-confirm && break || echo "Attempt $attempt failed, retrying in 60..."
sleep 60
done
echo "Sleeping for 60 seconds to handle rate limits..."
sleep 60
done
- name: Release Rust project
if: steps.extract-project.outputs.package != 'all' && steps.extract-project.outputs.language == 'rust'
shell: bash
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
PACKAGE: ${{ steps.extract-project.outputs.package }}
PACKAGE_SNAKE_CASE: ${{ steps.extract-project.outputs.package-snake-case }}
run: |
source ./scripts/devenv.sh
# Check whether we are building an on-chain program.
if [[ $(anchor keys list | grep "$PACKAGE_SNAKE_CASE") -eq 0 ]]; then
anchor build -p "$PACKAGE_SNAKE_CASE"
fi
cp -r ./target/deploy/*.so .
cargo release publish \
--package "$PACKAGE"
- name: Release TypeScript
if: steps.extract-project.outputs.package != 'all' && steps.extract-project.outputs.language == 'ts'
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
NPM_CONFIG_PROVENANCE: true
PACKAGE: ${{ steps.extract-project.outputs.package }}
run: |
SUBDIR=$(grep "$PACKAGE" pnpm-workspace.yaml | awk -F '"' '{gsub("/\\*\\*", "", $2); print $2}')
cd "$SUBDIR"
pnpm publish --access public --no-git-checks
- name: GitHub release
uses: softprops/action-gh-release@v2
if: steps.extract-project.outputs.language != ''
with:
token: ${{ secrets.PAT_TOKEN }}
files: |
*.so