-
Notifications
You must be signed in to change notification settings - Fork 4
103 lines (88 loc) · 2.9 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
name: Automatic Release Workflow
on:
push:
branches:
- main
jobs:
create_and_merge_pr:
name: Create and Merge PR Automatically
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Go environment
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.18'
# Step 3: Run `go mod tidy` and check for changes
- name: Run go mod tidy
run: |
go mod tidy
git config user.name "majidkarimizadeh"
git config user.email "[email protected]"
git diff --quiet || (
git checkout -b tidy-go-mod
git add go.mod go.sum
git commit -m "chore: tidy go.mod and go.sum"
)
# Step 4: Push changes (if any) to a new branch
- name: Push changes to branch
if: success()
run: |
git diff --quiet || git push origin tidy-go-mod
# Step 5: Create a pull request
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v5
with:
branch: tidy-go-mod
commit-message: "chore: tidy go.mod and go.sum"
title: "chore: tidy go.mod and go.sum"
body: "This PR ensures go.mod and go.sum are clean."
labels: "automerge"
# Step 6: Enable auto-merge for the PR
- name: Enable Auto-Merge
uses: "peter-evans/enable-pull-request-automerge@v2"
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ steps.create_pr.outputs.pull_request_number }}
merge-method: squash
release:
name: Release Go Project
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Go environment
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.18' # Specify your Go version
# Step 4: Tag the release
- name: Create a Git tag
run: |
VERSION="v0.0.1-$(git rev-parse --short HEAD)"
git tag -a $VERSION -m "Release $VERSION"
git push origin $VERSION
# Step 5: Run GoReleaser to create the release
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
automerge:
name: Enable Auto-Merge for Release Pull Requests
runs-on: ubuntu-latest
needs: release
steps:
- name: Enable Auto-Merge
uses: "peter-evans/enable-pull-request-automerge@v2"
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: squash