-
Notifications
You must be signed in to change notification settings - Fork 6
158 lines (136 loc) · 5.06 KB
/
Copy pathrelease-api.yml
File metadata and controls
158 lines (136 loc) · 5.06 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
name: Release API
on:
push:
tags:
- 'api/v[0-9]+.[0-9]+.[0-9]+*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/tron-api
jobs:
# Run tests before release
test:
name: Run Tests
uses: ./.github/workflows/tests.yml
with:
component: api
secrets: inherit
# Build and release only if tests pass
build-and-release:
runs-on: ubuntu-latest
needs: test
permissions:
contents: write
packages: write
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from tag
id: version
run: |
# Extract version from tag (api/v1.0.0 -> 1.0.0)
TAG=${GITHUB_REF#refs/tags/api/v}
echo "version=$TAG" >> $GITHUB_OUTPUT
echo "Version: $TAG"
# Extract major.minor for additional tags
MAJOR=$(echo $TAG | cut -d. -f1)
MINOR=$(echo $TAG | cut -d. -f2)
echo "major=$MAJOR" >> $GITHUB_OUTPUT
echo "minor=$MAJOR.$MINOR" >> $GITHUB_OUTPUT
# Check if it's a prerelease (contains - like 1.0.0-beta.1)
if [[ "$TAG" == *"-"* ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.version }}
type=raw,value=${{ steps.version.outputs.minor }},enable=${{ steps.version.outputs.prerelease == 'false' }}
type=raw,value=latest,enable=${{ steps.version.outputs.prerelease == 'false' }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
context: ./api
file: ./api/Dockerfile.prod
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=api
cache-to: type=gha,mode=max,scope=api
platforms: linux/amd64,linux/arm64
provenance: true
sbom: true
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
- name: Generate changelog
id: changelog
run: |
# Get the previous API tag
PREV_TAG=$(git tag -l 'api/v*' --sort=-v:refname | head -2 | tail -1)
if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" == "api/v${{ steps.version.outputs.version }}" ]; then
echo "changelog=Initial release" >> $GITHUB_OUTPUT
else
# Get commits between tags that affect the api directory
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD -- api/ | head -50)
if [ -z "$CHANGELOG" ]; then
CHANGELOG="No significant changes in API"
fi
# Use delimiter for multiline output
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: API v${{ steps.version.outputs.version }}
tag_name: api/v${{ steps.version.outputs.version }}
body: |
## API v${{ steps.version.outputs.version }}
### Docker Image
```bash
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
```
### Image Digest
`${{ steps.build.outputs.digest }}`
### Changes
${{ steps.changelog.outputs.changelog }}
### Installation
```bash
helm repo add grid-labs-tech https://grid-labs-tech.github.io/charts
helm repo update
helm upgrade --install tron grid-labs-tech/tron \
--set api.image.tag=${{ steps.version.outputs.version }}
```
### Verification
All tests passed before this release was published.
draft: false
prerelease: ${{ steps.version.outputs.prerelease == 'true' }}