update readme.md #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| permissions: | |
| contents: write | |
| actions: write | |
| jobs: | |
| test: | |
| name: Run Tests & Generate Coverage Badge | |
| runs-on: ubuntu-latest | |
| outputs: | |
| coverage: ${{ steps.coverage.outputs.coverage }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: 'go.mod' | |
| - name: Run Tests and Generate Coverage | |
| id: coverage | |
| run: | | |
| go test -v ./... -covermode=count -coverprofile=coverage.out | |
| COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') | |
| echo "Coverage: $COVERAGE%" | |
| echo "coverage=$COVERAGE" >> $GITHUB_ENV | |
| echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT | |
| if (( $(echo "$COVERAGE < 80" | bc -l) )); then | |
| echo "Test coverage is below 80%, failing the build." | |
| exit 1 | |
| fi | |
| go tool cover -func=coverage.out -o=coverage.out | |
| - name: Go Coverage Badge | |
| uses: tj-actions/coverage-badge-go@v3 | |
| with: | |
| filename: coverage.out | |
| coverage: ${{ env.coverage }} | |
| - name: Verify Changed Files | |
| uses: tj-actions/verify-changed-files@v16 | |
| id: verify-changed-files | |
| with: | |
| files: README.md | |
| - name: Commit Changes | |
| if: steps.verify-changed-files.outputs.files_changed == 'true' | |
| run: | | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| git add README.md | |
| git commit -m "chore: Updated coverage badge." | |
| - name: Push Changes | |
| if: steps.verify-changed-files.outputs.files_changed == 'true' | |
| uses: ad-m/github-push-action@master | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: ${{ github.head_ref }} | |
| release: | |
| name: Create Release | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Fetch All Tags | |
| run: git fetch --tags | |
| - name: Determine Latest Tag and Bump Version | |
| id: version | |
| run: | | |
| latest_tag=$(git describe --tags --abbrev=0 || echo "v0.0.0") | |
| echo "Latest tag: $latest_tag" | |
| IFS='.' read -r major minor patch <<<"${latest_tag#v}" | |
| new_tag="v$major.$minor.$((patch + 1))" | |
| git tag "$new_tag" | |
| git push origin "$new_tag" | |
| echo "tag=$new_tag" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Release with Notes | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| name: ${{ steps.version.outputs.tag }} | |
| generate_release_notes: true | |
| body: | | |
| 🚀 **Automated Release** | |
| - **Triggered by:** [@${{ github.actor }}](https://github.com/${{ github.actor }}) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |