-
-
Notifications
You must be signed in to change notification settings - Fork 1
125 lines (108 loc) · 3.59 KB
/
cd.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
name: CD
on:
push:
tags:
- "v*"
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.23"
- name: Install dependencies
run: go mod download
- name: Run tests
run: go test -v ./...
- name: Build
run: |
GOOS=linux GOARCH=amd64 go build -o sqlmapper-linux-amd64
GOOS=darwin GOARCH=amd64 go build -o sqlmapper-darwin-amd64
GOOS=windows GOARCH=amd64 go build -o sqlmapper-windows-amd64.exe
- name: Generate changelog
id: changelog
uses: actions/github-script@v6
with:
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
})
const previous = releases[0]?.tag_name
const current = context.ref.replace('refs/tags/', '')
const { data: commits } = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: previous || '',
head: current,
})
const changelog = commits.commits
.map(commit => `- ${commit.commit.message}`)
.join('\n')
return changelog
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Changes in this Release:
${{ steps.changelog.outputs.result }}
draft: false
prerelease: false
- name: Upload Linux Binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sqlmapper-linux-amd64
asset_name: sqlmapper-linux-amd64
asset_content_type: application/octet-stream
- name: Upload macOS Binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sqlmapper-darwin-amd64
asset_name: sqlmapper-darwin-amd64
asset_content_type: application/octet-stream
- name: Upload Windows Binary
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./sqlmapper-windows-amd64.exe
asset_name: sqlmapper-windows-amd64.exe
asset_content_type: application/octet-stream
docker:
name: Push Docker image
runs-on: ubuntu-latest
needs: release
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
mstgnz/sqlmapper:latest
mstgnz/sqlmapper:${{ github.ref_name }}