commit new version 0.5.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: Create Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| create-release: | |
| if: | | |
| contains(github.event.head_commit.message, 'commit new version') == true | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release_upload_url: ${{ steps.create-release.outputs.upload_url }} | |
| version: ${{ steps.extract-version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Extract Version | |
| id: extract-version | |
| run: | | |
| # Use grep to find the first occurrence of the version number matching "## 0.0.0" pattern | |
| version=$(grep -m 1 -oP '## \d+\.\d+\.\d+' CHANGELOG.md | cut -d ' ' -f 2) | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| - name: Extract Changelog | |
| id: extract-changelog | |
| run: | | |
| # Extract the content between the last two version headers | |
| changelog=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+/{if (!version) {version=$0; next}} /^## [0-9]+\.[0-9]+\.[0-9]+/{exit} {if (version) description = description ORS $0} END {if (version) print description}' CHANGELOG.md | sed -e '/^## [0-9]+\.[0-9]+\.[0-9]+/d; s/^# //' > changelog.txt) | |
| echo "changelog_file=changelog.txt" >> "$GITHUB_OUTPUT" | |
| - name: Create Release | |
| id: create-release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.extract-version.outputs.version }} | |
| release_name: ${{ steps.extract-version.outputs.version }} | |
| body_path: ${{ steps.extract-changelog.outputs.changelog_file }} | |
| draft: false | |
| prerelease: false | |
| build-and-upload: | |
| if: | | |
| contains(github.event.head_commit.message, 'commit new version') == true | |
| needs: create-release | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - os: linux | |
| arch: amd64 | |
| ext: "" | |
| - os: linux | |
| arch: arm64 | |
| ext: "" | |
| - os: windows | |
| arch: amd64 | |
| ext: ".exe" | |
| - os: windows | |
| arch: arm64 | |
| ext: ".exe" | |
| - os: darwin | |
| arch: amd64 | |
| ext: "" | |
| - os: darwin | |
| arch: arm64 | |
| ext: "" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Build Binary | |
| env: | |
| GOOS: ${{ matrix.os }} | |
| GOARCH: ${{ matrix.arch }} | |
| CGO_ENABLED: 0 | |
| run: | | |
| go build \ | |
| -ldflags "-s -w" \ | |
| -o "docker-ztd-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}" \ | |
| ./cmd/docker-ztd | |
| - name: Upload Release Asset | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ needs.create-release.outputs.release_upload_url }} | |
| asset_path: ./docker-ztd-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} | |
| asset_name: docker-ztd-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} | |
| asset_content_type: application/octet-stream |