Skip to content

Commit

Permalink
Merge pull request #8 from btnguyen2k/dev
Browse files Browse the repository at this point in the history
Test release
  • Loading branch information
btnguyen2k authored Nov 23, 2023
2 parents 6a1df58 + 941454c commit 2a7d92b
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 163 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ on:
jobs:
Test:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18', 'oldstable', 'stable' ]
name: Run tests with Go ${{ matrix.go }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go env
uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Check out code
uses: actions/checkout@v4
go-version: ${{ matrix.go }}
- name: Run tests
run: |
go version
go test -v -timeout 9999s -count 1 -p 1 -cover -coverprofile coverage.txt .
- name: Codecov
uses: codecov/codecov-action@v3
with:
flags: generic
name: generic
177 changes: 87 additions & 90 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,107 +7,104 @@ on:
types: [ "completed" ]

jobs:
Test:
ReleaseDryRun:
runs-on: ubuntu-latest
steps:
- name: Set up Go env
uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Check out code
uses: actions/checkout@v4
- name: Run tests
run: |
export CHECK_RELEASE_VERSION=true
go test -v -timeout 9999s -count 1 -p 1 .
Release:
# if: |
# github.event.repository.fork == false &&
# github.event.workflow_run.event == 'pull_request' &&
# github.event.workflow_run.conclusion == 'success' &&
# github.event.pull_request.merged == true &&
# github.ref == 'refs/heads/release'
needs: [ Test ]
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
# if: |
# github.event.repository.fork == false &&
# github.event.workflow_run.event == 'pull_request' &&
# github.event.workflow_run.conclusion == 'success' &&
# github.event.pull_request.merged == true &&
# github.ref == 'refs/heads/release'
# permissions:
# contents: write # to be able to publish a GitHub release
# issues: write # to be able to comment on released issues
# pull-requests: write # to be able to comment on released pull requests
outputs:
RESULT: ${{ steps.release_dry_run.outputs.result }}
VERSION: ${{ steps.release_dry_run.outputs.releaseVersion }}
RELEASE_NOTES: ${{ steps.release_dry_run.outputs.releaseNotes }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Dummy
run: |
pwd
ls -l
node -v
- name: Release
uses: actions/github-script@v7
- name: Release (dry-run)
id: release_dry_run
uses: btnguyen2k/action-semrelease@v3
with:
dry-run: true
auto-mode: true
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log('Parsing release notes... 🕜');
const fileReleaseNotes = './RELEASE-NOTES.md';
const reSemver = /^#+.*?[\s:-]v?((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/;
const fs = require('fs/promises');
const file = await fs.open(`${fileReleaseNotes}`, `r`);
const releaseNotes = []
let enterReleaseNotes = false;
let version = '';
for await (const line of file.readLines({encoding: 'utf8'})) {
const matches = line.match(reSemver)
if (matches) {
if (enterReleaseNotes) {
break;
}
enterReleaseNotes = true;
version = matches[1];
} else if (enterReleaseNotes) {
releaseNotes.push(line);
}
}
if (version === '') {
console.log('Stop 🚫');
console.log(`No release version found in file <${fileReleaseNotes}>.`);
return;
}
const tagName = `v${version}`;
# const tag = await github.rest.tags.get({
# owner: context.repo.owner,
# repo: context.repo.repo,
# pull_number: pr_number,
# });

tag-major-release: false
tag-minor-release: false
branches: 'release'
tag-prefix: 'v'
tag-only: true

# const releaseNotesData = fs.readFileSync('./RELEASE-NOTES.md', 'utf8');
# console.log(releaseNotesData);

# if (!context.payload.pull_request && (!context.payload.workflow_run.pull_requests || context.payload.workflow_run.pull_requests.length === 0)) {
# console.log('Not Merged 🚫');
# console.log('No pull_request found in payload.');
# return;
# uses: actions/github-script@v7
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# console.log('Parsing release notes... 🕜');
#
# const fileReleaseNotes = './RELEASE-NOTES.md';
# const reSemver = /^#+.*?[\s:-]v?((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/;
# const fs = require('fs/promises');
# const file = await fs.open(`${fileReleaseNotes}`, `r`);
# const releaseNotes = []
# let enterReleaseNotes = false;
# let version = '';
# for await (const line of file.readLines({encoding: 'utf8'})) {
# const matches = line.match(reSemver)
# if (matches) {
# if (enterReleaseNotes) {
# break;
# }
# enterReleaseNotes = true;
# version = matches[1];
# } else if (enterReleaseNotes) {
# releaseNotes.push(line);
# }
# }
# const pr_number = context.payload.pull_request ? context.payload.pull_request.number : context.payload.workflow_run.pull_requests[0].number
# console.log(`Merging PR <${pr_number}>... 🕜`);
# const pr = await github.rest.pulls.get({
# owner: context.repo.owner,
# repo: context.repo.repo,
# pull_number: pr_number,
# });
# if (pr.data.user.login !== 'dependabot[bot]') {
# console.log('Not Merged 🚫');
# console.log(`User <${pr.data.user.login}> does not equal <dependabot[bot]>`);
# } else {
# await github.rest.pulls.merge({
# owner: context.repo.owner,
# repo: context.repo.repo,
# pull_number: pr_number,
# });
# console.log('Merged 🎉');
# if (version === '') {
# console.log('Stop 🚫');
# console.log(`No release version found in file <${fileReleaseNotes}>.`);
# return;
# }
# const tagName = `v${version}`;
## const tag = await github.rest.tags.get({
# # owner: context.repo.owner,
# # repo: context.repo.repo,
# # pull_number: pr_number,
# # });
#
#
## const releaseNotesData = fs.readFileSync('./RELEASE-NOTES.md', 'utf8');
## console.log(releaseNotesData);
#
## if (!context.payload.pull_request && (!context.payload.workflow_run.pull_requests || context.payload.workflow_run.pull_requests.length === 0)) {
## console.log('Not Merged 🚫');
## console.log('No pull_request found in payload.');
## return;
## }
## const pr_number = context.payload.pull_request ? context.payload.pull_request.number : context.payload.workflow_run.pull_requests[0].number
## console.log(`Merging PR <${pr_number}>... 🕜`);
## const pr = await github.rest.pulls.get({
## owner: context.repo.owner,
## repo: context.repo.repo,
## pull_number: pr_number,
## });
## if (pr.data.user.login !== 'dependabot[bot]') {
## console.log('Not Merged 🚫');
## console.log(`User <${pr.data.user.login}> does not equal <dependabot[bot]>`);
## } else {
## await github.rest.pulls.merge({
## owner: context.repo.owner,
## repo: context.repo.repo,
## pull_number: pr_number,
## });
## console.log('Merged 🎉');
## }
21 changes: 21 additions & 0 deletions LICENSE.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) <year> <your name>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# go-module-template

Template to quickly spin up a Go module project
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Actions Status](https://github.com/btnguyen2k/go-module-template/workflows/ci/badge.svg)](https://github.com/btnguyen2k/go-module-template/actions)
[![Release](https://img.shields.io/github/release/btnguyen2k/go-module-template.svg?style=flat-square)](RELEASE-NOTES.md)

Template to quickly spin up a Go module project.

## Features

- [Go modules](https://blog.golang.org/using-go-modules) enabled.
- Template for README, LICENSE, RELEASE-NOTES, and .gitignore files.
- GitHub actions included:
- `dependabot.yaml`, `automerge-dependabot.yaml`: automatically update dependencies and merge PRs from dependabot.
- `ci.yaml`: automatically run tests and generate code coverage report.
- `release.yaml`: automatically create a new release.

**Default workflow**

- Dependencies are checked and updated weekly by `dependabot.yaml`, and then PRs are automatically merged to `main` branch by `automerge-dependabot.yaml`.
- `ci.yaml` is triggered on every push to any branch to run tests and generate code coverage report.
- Once PR is approved and merged to `release` branch, `release.yaml` is triggered to create a new release. Then a new PR is created to merge `release` branch to `main` branch.

## Usage

1. Create new project from this template:
- Click on the `Use this template` button to create a new repository from this template.
- Or use the `gh` command line tool: `gh repo create <your-repository> --template btnguyen2k/go-module-template`
- (Less preferred method) Or simply clone/fork this repository.
2. Update `go.mod` and `module.go` file to reflect your module name and required Go version.
3. Review other source code and test files, either update them to reflect your module's name and functionality or remove them.
4. `LICENSE.tpl.md`, `README.tpl.md` and `RELEASE-NOTES.tpl.md` files are templates. Update them to reflect your module's name and functionality. Then rename them to `LICENSE.md`, `README.md` and `RELEASE-NOTES.md`.
5. Update other files to suit your needs.
6. Happy coding!

## License

This template is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

## Contributing & Support

Feel free to create [pull requests](https://github.com/btnguyen2k/go-module-template/pulls) or [issues](https://github.com/btnguyen2k/go-module-template/issues) to report bugs or suggest new features. If you find this project useful, please start it.
64 changes: 64 additions & 0 deletions README.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# <Your Module Name>

[![Go Report Card](https://goreportcard.com/badge/github.com/<your-username>/<your-repository>)](https://goreportcard.com/report/github.com/<your-username>/<your-repository>)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/<your-username>/<your-repository>)](https://pkg.go.dev/github.com/<your-username>/<your-repository>)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Actions Status](https://github.com/<your-username>/<your-repository>/workflows/ci/badge.svg)](https://github.com/<your-username>/<your-repository>/actions)
[![codecov](https://codecov.io/gh/<your-username>/<your-repository>/branch/main/graph/badge.svg)](https://codecov.io/gh/<your-username>/<your-repository>)
[![Release](https://img.shields.io/github/release/<your-username>/<your-repository>.svg?style=flat-square)](RELEASE-NOTES.md)

A brief description of your Go module, its purpose, and any key features.

## Installation

To use this module in your Go project, you can use the `go get` command:

```bash
$ go get -u github.com/<your-username>/<your-repository>
```

## Usage

Explain how users can import and use your module in their Go projects. Provide code examples if necessary.

```go
package main

import (
"fmt"
"github.com/<your-username>/<your-repository>"
)

func main() {
// Example usage
fmt.Println(your_module_name.YourFunction())
}
```

## Configuration

If your module has configuration options, document them here.

## Contributing

Explain how others can contribute to your project. Include guidelines for reporting issues, submitting feature requests, and making pull requests.

## License

This project is licensed under the MIT License - see the [LICENSE.tpl.md](LICENSE.tpl.md) file for details.

## Acknowledgments

Give credit to any contributors, libraries, or tools that your module depends on.

## Contact

Provide your contact information for users who may have questions or want to get in touch with you.

## Release History

See the [RELEASE-NOTES.tpl.md](RELEASE-NOTES.tpl.md) file for details.

## Support

If you encounter any issues or have questions, feel free to [create an issue](https://github.com/<your-username>/<your-repository>/issues).
21 changes: 21 additions & 0 deletions RELEASE-NOTES.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# <Your Module Name> release notes

## yyyy-MM-dd - v0.1.0

### Changed

- Change: any change to existing functions

### Added/Refactoring

- Feature: new features
- Added: new functions.
- etc

### Fixed/Improvement

- Fix: Bug #123

### Others

- Docs: documentation updates
Loading

0 comments on commit 2a7d92b

Please sign in to comment.