-
Notifications
You must be signed in to change notification settings - Fork 2
127 lines (110 loc) · 4.1 KB
/
Copy pathrelease.yml
File metadata and controls
127 lines (110 loc) · 4.1 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
name: tag and release
on:
push:
branches:
- main
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Get version
id: get_version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0")
echo "current_version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate new tag
id: new_tag
run: |
CURRENT_VERSION=${{ steps.get_version.outputs.current_version }}
MAJOR=$(echo $CURRENT_VERSION | cut -d'.' -f1 | tr -d 'v')
MINOR=$(echo $CURRENT_VERSION | cut -d'.' -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d'.' -f3)
# Get commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
# Determine version bump based on conventional commit type
if [[ $COMMIT_MSG == *"!"* ]]; then
# Breaking change = major version bump
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
elif [[ $COMMIT_MSG == feat:* ]]; then
# New feature = minor version bump
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
elif [[ $COMMIT_MSG == fix:* ]] || [[ $COMMIT_MSG == chore:* ]] || [[ $COMMIT_MSG == docs:* ]]; then
# Bug fix, chore, or docs = patch version bump
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
else
# Default to patch bump for unknown types
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
fi
NEW_TAG="v${NEW_MAJOR}.${NEW_MINOR}.${NEW_PATCH}"
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
- name: Build
run: |
VERSION=${{ steps.new_tag.outputs.new_tag }}
LDFLAGS="-X main.binVersion=${VERSION}"
GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o bin/viztruct-linux-amd64 ./cmd/viztruct
GOOS=linux GOARCH=arm64 go build -ldflags "${LDFLAGS}" -o bin/viztruct-linux-arm64 ./cmd/viztruct
GOOS=darwin GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o bin/viztruct-darwin-amd64 ./cmd/viztruct
GOOS=darwin GOARCH=arm64 go build -ldflags "${LDFLAGS}" -o bin/viztruct-darwin-arm64 ./cmd/viztruct
- name: Create tag
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
git config --local user.name "${{ github.actor }}"
git tag ${{ steps.new_tag.outputs.new_tag }}
git push origin ${{ steps.new_tag.outputs.new_tag }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.new_tag.outputs.new_tag }}
files: |
bin/viztruct-darwin-amd64
bin/viztruct-darwin-arm64
bin/viztruct-linux-amd64
bin/viztruct-linux-arm64
generate_release_notes: true
draft: false
prerelease: false
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get image and tags
id: meta
uses: docker/metadata-action@v5
with:
images: buarki/viztruct-plugin
tags: |
type=sha
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v6
with:
file: ./cmd/ci-plugin/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}