Skip to content

Commit

Permalink
🔇 silent changes: refactor CI.CD #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 20, 2024
1 parent 88dbb56 commit 906ec11
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
50 changes: 35 additions & 15 deletions .github/workflows/go.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,37 @@ name: Go

on:
push:
branches: [ "master" ]
branches: ["master"]
tags:
- "v*"
pull_request:
branches: [ "master" ]
branches: ["master"]

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
# Add Go versions as needed
go: ["1.19", "1.20.x", "1.21.x"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
- name: Test
run: go test -v ./...

create-release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') # Only run this job when a valid tag is pushed
# Only run this job when a valid tag is pushed
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Check if tag exists
id: check_tag
Expand All @@ -46,15 +50,31 @@ jobs:
fi
shell: bash

- name: Checkout code
uses: actions/checkout@v3
with:
# Ensure all history is fetched
fetch-depth: 0

- name: Apply changelog
run: chmod +x git_changelog.sh

- name: Generate changelog
id: changelog
run: |
CHANGELOG=$(./git_changelog.sh)
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
# tag_name: ${{ steps.check_tag.outputs.tag }}
tag_name: ${{ env.TAG }}
body: |
:gem: released new version ${{ env.TAG }}
Changelog:
${{ env.CHANGELOG }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions git_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Get the hash of the last tag
tag_hash_latest=$(git rev-list --tags --max-count=1)
# Get the tag name associated with that hash
tag_latest=$(git describe --tags "$tag_hash_latest")
# Get the commit messages from that tag to the current commit
CHANGELOG=$(git log "$tag_latest"..HEAD --pretty=format:"- %h %s")
# Print the changelog
echo "$CHANGELOG"

0 comments on commit 906ec11

Please sign in to comment.