forked from Cogwheel-Validator/spectra-gnoland-indexer
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (139 loc) · 6.3 KB
/
Copy pathrelease.yml
File metadata and controls
164 lines (139 loc) · 6.3 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
name: Release
on:
push:
tags:
- "v*"
jobs:
build-and-release:
name: Build and Release
permissions:
contents: write
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4
with:
go-version: "1.26.4"
- name: Get version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if this is a pre-release (contains alpha, beta, rc, etc.)
if [[ $VERSION =~ (alpha|beta|rc) ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
echo "docker_tag=dev" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
echo "docker_tag=latest" >> $GITHUB_OUTPUT
fi
- name: Get git metadata
id: gitmeta
run: |
# actions/checkout provides the .git directory so these commands will work
echo "git_commit=$(git rev-parse --short HEAD 2>/dev/null || echo unknown)" >> $GITHUB_OUTPUT
echo "git_tag=$(git describe --tags --exact-match 2>/dev/null || echo)" >> $GITHUB_OUTPUT
echo "git_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo)" >> $GITHUB_OUTPUT
- name: Install arm64 cross-compiler
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Build binaries
env:
GIT_COMMIT: ${{ steps.gitmeta.outputs.git_commit }}
GIT_TAG: ${{ steps.gitmeta.outputs.git_tag }}
GIT_BRANCH: ${{ steps.gitmeta.outputs.git_branch }}
VERSION_INPUT: ${{ steps.version.outputs.version }}
run: |
mkdir -p build
# Compute VERSION (prefer tag, otherwise branch-commit)
if [ -n "$GIT_TAG" ]; then
VERSION="$GIT_TAG"
else
VERSION="${GIT_BRANCH}-${GIT_COMMIT}"
fi
echo "Building with VERSION=$VERSION, GIT_COMMIT=$GIT_COMMIT"
go mod download
LDFLAGS_INDEXER="-X github.com/Cogwheel-Validator/spectra-gnoland-indexer/indexer/cmd.Commit=${GIT_COMMIT} -X github.com/Cogwheel-Validator/spectra-gnoland-indexer/indexer/cmd.Version=${VERSION} -w -s"
LDFLAGS_API="-X main.Commit=${GIT_COMMIT} -X main.Version=${VERSION} -w -s"
# amd64
GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS_INDEXER" -o build/indexer-linux-amd64 indexer/cmd/indexer.go
GOOS=linux GOARCH=amd64 go build -ldflags="$LDFLAGS_API" -o build/api-linux-amd64 api/*.go
# arm64
GOOS=linux GOARCH=arm64 go build -ldflags="$LDFLAGS_INDEXER" -o build/indexer-linux-arm64 indexer/cmd/indexer.go
GOOS=linux GOARCH=arm64 go build -ldflags="$LDFLAGS_API" -o build/api-linux-arm64 api/*.go
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: build/*
prerelease: ${{ steps.version.outputs.prerelease }}
generate_release_notes: true
body: |
## Release ${{ steps.version.outputs.version }}
### Installation for the indexer
Download the binary for your platform and make it executable:
```bash
chmod +x indexer-*
```
You will need to set up the database for the indexer, check the docs for more information.
To generate a default config use:
```bash
indexer setup create-config
```
This will create a config.yml in the current directory.
When you have the database running run the cmd to create the database and the user.
```bash
indexer setup create-db --db-host localhost --db-port 5432 --db-user postgres --db-name postgres --ssl-mode disable --new-db-name gnoland --chain-name gnoland
indexer setup create-user --db-host localhost --db-port 5432 --db-user postgres --db-name postgres --ssl-mode disable --user writer --privilege writer
```
From here you can run the indexer using live or historic mode
```bash
./indexer run live --config config.yml
./indexer run historic --config config.yml --from-height 1 --to-height 2000
```
For more information check the docs.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker Indexer image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
platforms: linux/amd64
tags: |
ghcr.io/cogwheel-validator/spectra-gnoland-indexer:${{ steps.version.outputs.version }}
ghcr.io/cogwheel-validator/spectra-gnoland-indexer:${{ steps.version.outputs.docker_tag }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
GIT_COMMIT=${{ steps.gitmeta.outputs.git_commit }}
GIT_TAG=${{ steps.gitmeta.outputs.git_tag }}
GIT_BRANCH=${{ steps.gitmeta.outputs.git_branch }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push Docker API image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile-api
push: true
platforms: linux/amd64
tags: |
ghcr.io/cogwheel-validator/spectra-gnoland-api:${{ steps.version.outputs.version }}
ghcr.io/cogwheel-validator/spectra-gnoland-api:${{ steps.version.outputs.docker_tag }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
GIT_COMMIT=${{ steps.gitmeta.outputs.git_commit }}
GIT_TAG=${{ steps.gitmeta.outputs.git_tag }}
GIT_BRANCH=${{ steps.gitmeta.outputs.git_branch }}
cache-from: type=gha
cache-to: type=gha,mode=max