Skip to content

Commit

Permalink
feat: setup golang with cache action
Browse files Browse the repository at this point in the history
  • Loading branch information
ArielSantos01 committed Dec 23, 2024
1 parent 3760083 commit 0788f3d
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 11 deletions.
15 changes: 15 additions & 0 deletions .cz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool]
[tool.commitizen]
name = "cz_customize"
version = "0.3.0"
tag_format = "v$version"
bump_message = "bump: release $current_version → $new_version [skip-ci]"
update_changelog_on_bump = true
version_files = [
"package.json:version",
]

[tool.commitizen.customize]
schema_pattern = "(break|build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump|deps)(\\(\\S+\\))?!?:(\\s.*)"
bump_pattern = "^(break|build|feat|fix|refactor|style|test|revert|deps|docs|ci|chore)"
bump_map = {"break" = "MAJOR", "build" = "MINOR", "feat" = "MINOR", "revert" = "MINOR", "fix" = "PATCH", "refactor" = "PATCH", "style" = "PATCH", "test" = "PATCH", "ci" = "PATCH", "deps" = "PATCH", "chore" = "PATCH", "docs" = "PATCH"}
18 changes: 18 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.

## Task Context

### What is the current behavior?

<!-- current functionality without PR -->

### What is the new behavior?

<!-- expected functionality with PR -->

### Additional Context

<!-- Add here any additional context you think is important. -->
25 changes: 25 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pull Request

on:
pull_request:

jobs:
commit_lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]
with:
token: "${{ secrets.ACCESS_TOKEN }}"
fetch-depth: 0

- name: Setup Python
uses: actions/[email protected]
with:
python-version: 3.11

- name: Install Commitizen
run: pip install -U commitizen

- name: Check commits
run: cz check --rev-range origin/main..HEAD
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release

on:
push:
branches:
- main

env:
GIT_USER_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_USER_NAME: ${{ secrets.GIT_NAME }}

permissions:
contents: write

jobs:
bump_version:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
runs-on: ubuntu-latest
name: "Bump version"
outputs:
version: ${{ steps.cz.outputs.version }}
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: "${{ secrets.ACCESS_TOKEN }}"
ref: "main"

- name: Set up Python
uses: actions/[email protected]
with:
python-version: 3.11

- name: Config Git User
run: |
git config --local user.email "$GIT_USER_EMAIL"
git config --local user.name "$GIT_USER_NAME"
git config --local pull.ff only
- id: cz
name: Create bump and changelog
run: |
python -m pip install -U commitizen
cz bump --yes
export REV=`cz version --project`
echo "version=\"v$REV\"" >> $GITHUB_OUTPUT
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
repository: "Drafteame/node-cache-action"
branch: "main"
directory: .
tags: true

- name: Print Version
run: echo "Bumped to version ${{ steps.cz.outputs.version }}"
11 changes: 0 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env
Empty file added README.md
Empty file.
52 changes: 52 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Golang with cache
author: Draftea
description: Setup requested Golang version with managed modules caching.

inputs:
go-version:
description: Desired Golang version.
default:
go-version-file:
description: Path to go.mod file, will determine Golang version. Use in place of `go-version` input.
default:
cache-key-suffix:
description: Optional cache key suffix.
default:

outputs:
build-cache-path:
description: Golang build cache path.
value: ${{ steps.golang-env.outputs.build-cache-path }}
module-cache-path:
description: Golang module cache path.
value: ${{ steps.golang-env.outputs.module-cache-path }}
cache-key:
description: Cache key holding Golang build and module cache paths.
value: ${{ steps.golang-env.outputs.cache-key }}

runs:
using: composite
steps:
- name: Setup Golang
uses: useblacksmith/setup-go@v6
with:
cache: false
go-version: ${{ inputs.go-version }}
- name: Determine Golang cache paths and construct cache key
id: golang-env
run: |
echo "build-cache-path=$(go env GOCACHE)" >>"$GITHUB_OUTPUT"
echo "module-cache-path=$(go env GOMODCACHE)" >>"$GITHUB_OUTPUT"
cacheKeyRoot="${{ runner.os }}-golang${{ inputs.cache-key-suffix && format('-{0}',inputs.cache-key-suffix) }}-"
echo "cache-key-restore=$cacheKeyRoot" >>"$GITHUB_OUTPUT"
echo "cache-key=${cacheKeyRoot}${{ hashFiles('**/go.sum') }}" >>"$GITHUB_OUTPUT"
shell: bash
- name: Setup Golang cache
uses: useblacksmith/cache@v5
with:
path: |
${{ steps.golang-env.outputs.build-cache-path }}
${{ steps.golang-env.outputs.module-cache-path }}
key: ${{ steps.golang-env.outputs.cache-key }}
restore-keys: |
${{ steps.golang-env.outputs.cache-key-restore }}

0 comments on commit 0788f3d

Please sign in to comment.