Skip to content

Commit 906ec11

Browse files
committed
🔇 silent changes: refactor CI.CD #2
1 parent 88dbb56 commit 906ec11

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

.github/workflows/go.yml renamed to .github/workflows/ci.yml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,37 @@ name: Go
55

66
on:
77
push:
8-
branches: [ "master" ]
8+
branches: ["master"]
99
tags:
1010
- "v*"
1111
pull_request:
12-
branches: [ "master" ]
12+
branches: ["master"]
1313

1414
jobs:
15-
1615
build:
1716
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
# Add Go versions as needed
20+
go: ["1.19", "1.20.x", "1.21.x"]
1821
steps:
19-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v3
2023

21-
- name: Set up Go
22-
uses: actions/setup-go@v3
23-
with:
24-
go-version: 1.19
24+
- name: Set up Go
25+
uses: actions/setup-go@v3
26+
with:
27+
go-version: ${{ matrix.go }}
2528

26-
- name: Build
27-
run: go build -v ./...
29+
- name: Build
30+
run: go build -v ./...
2831

29-
- name: Test
30-
run: go test -v ./...
32+
- name: Test
33+
run: go test -v ./...
3134

3235
create-release:
3336
runs-on: ubuntu-latest
34-
if: startsWith(github.ref, 'refs/tags/v') # Only run this job when a valid tag is pushed
37+
# Only run this job when a valid tag is pushed
38+
if: startsWith(github.ref, 'refs/tags/v')
3539
steps:
3640
- name: Check if tag exists
3741
id: check_tag
@@ -46,15 +50,31 @@ jobs:
4650
fi
4751
shell: bash
4852

53+
- name: Checkout code
54+
uses: actions/checkout@v3
55+
with:
56+
# Ensure all history is fetched
57+
fetch-depth: 0
58+
59+
- name: Apply changelog
60+
run: chmod +x git_changelog.sh
61+
62+
- name: Generate changelog
63+
id: changelog
64+
run: |
65+
CHANGELOG=$(./git_changelog.sh)
66+
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
67+
4968
- name: Create GitHub Release
5069
id: create_release
5170
uses: softprops/action-gh-release@v1
5271
with:
53-
# tag_name: ${{ steps.check_tag.outputs.tag }}
5472
tag_name: ${{ env.TAG }}
5573
body: |
5674
:gem: released new version ${{ env.TAG }}
75+
Changelog:
76+
${{ env.CHANGELOG }}
5777
draft: false
5878
prerelease: false
5979
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

git_changelog.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Get the hash of the last tag
4+
tag_hash_latest=$(git rev-list --tags --max-count=1)
5+
# Get the tag name associated with that hash
6+
tag_latest=$(git describe --tags "$tag_hash_latest")
7+
# Get the commit messages from that tag to the current commit
8+
CHANGELOG=$(git log "$tag_latest"..HEAD --pretty=format:"- %h %s")
9+
# Print the changelog
10+
echo "$CHANGELOG"

0 commit comments

Comments
 (0)