Add CI/CD pipelines and bump version to 0.1.1 #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: Release | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - VERSION | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-version: | |
| name: Check version change | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| tag_exists: ${{ steps.check_tag.outputs.exists }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Read version | |
| id: version | |
| run: echo "version=$(cat VERSION | tr -d '[:space:]')" >> "$GITHUB_OUTPUT" | |
| - name: Check if tag already exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| needs: check-version | |
| if: needs.check-version.outputs.tag_exists == 'false' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Run tests | |
| run: go test -race ./... | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| needs: [check-version, test] | |
| if: needs.check-version.outputs.tag_exists == 'false' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Create and push tag | |
| env: | |
| VERSION: ${{ needs.check-version.outputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "v${VERSION}" -m "Release v${VERSION}" | |
| git push origin "v${VERSION}" | |
| - name: Run GoReleaser | |
| uses: goreleaser/goreleaser-action@v6 | |
| with: | |
| version: latest | |
| args: release --clean | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |