From 0788f3df389ba45667c35f66355f16a7923f9ac9 Mon Sep 17 00:00:00 2001 From: Ariel Santos Date: Mon, 23 Dec 2024 12:09:27 -0300 Subject: [PATCH] feat: setup golang with cache action --- .cz.toml | 15 ++++++++ .github/pull_request_template.md | 18 +++++++++ .github/workflows/pull_request.yml | 25 +++++++++++++ .github/workflows/release.yml | 59 ++++++++++++++++++++++++++++++ .gitignore | 11 ------ README.md | 0 action.yml | 52 ++++++++++++++++++++++++++ 7 files changed, 169 insertions(+), 11 deletions(-) create mode 100644 .cz.toml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/release.yml create mode 100644 README.md create mode 100644 action.yml diff --git a/.cz.toml b/.cz.toml new file mode 100644 index 0000000..c54f255 --- /dev/null +++ b/.cz.toml @@ -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"} diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..ef2d2ea --- /dev/null +++ b/.github/pull_request_template.md @@ -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? + + + +### What is the new behavior? + + + +### Additional Context + + diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..a897c5d --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,25 @@ +name: Pull Request + +on: + pull_request: + +jobs: + commit_lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3.3.0 + with: + token: "${{ secrets.ACCESS_TOKEN }}" + fetch-depth: 0 + + - name: Setup Python + uses: actions/setup-python@v4.7.0 + with: + python-version: 3.11 + + - name: Install Commitizen + run: pip install -U commitizen + + - name: Check commits + run: cz check --rev-range origin/main..HEAD diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..01fe92c --- /dev/null +++ b/.github/workflows/release.yml @@ -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/setup-python@v5.1.0 + 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/github-push-action@v0.6.0 + 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 }}" diff --git a/.gitignore b/.gitignore index 6f72f89..afa37f2 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..9e98adb --- /dev/null +++ b/action.yml @@ -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 }} \ No newline at end of file