master #1
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: Test and release library | |
| on: | |
| push: | |
| branches: ["master"] | |
| pull_request: | |
| branches: ["master"] | |
| permissions: | |
| contents: write | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Run Tests | |
| run: go test ./... -v | |
| release: | |
| name: Tag and Release | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: success() | |
| steps: | |
| - name: Checkout full history | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get latest tag | |
| id: get_tag | |
| run: | | |
| git fetch --tags | |
| latest_tag=$(git tag --sort=-v:refname | head -n 1) | |
| echo "latest_tag=${latest_tag:-v0.0.0}" >> $GITHUB_OUTPUT | |
| - name: Bump patch version | |
| id: bump | |
| run: | | |
| latest=${{ steps.get_tag.outputs.latest_tag }} | |
| IFS='.' read -r major minor patch <<<"${latest//v/}" | |
| patch=$((patch+1)) | |
| new_tag="v${major}.${minor}.${patch}" | |
| echo "new_tag=$new_tag" >> $GITHUB_OUTPUT | |
| - name: Create and push tag | |
| id: tag | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| git tag ${{ steps.bump.outputs.new_tag }} | |
| git push origin ${{ steps.bump.outputs.new_tag }} | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.bump.outputs.new_tag }} | |
| name: Release ${{ steps.bump.outputs.new_tag }} | |
| generate_release_notes: true |