|
| 1 | +name: Go module release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Go module version (e.g., 8.0.0.1)' |
| 8 | + required: true |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - 'v[0-9]*.[0-9]*.[0-9]*.[0-9]*' |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + name: Create Go module release |
| 19 | + runs-on: ubuntu-24.04 |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Validate version format |
| 23 | + if: github.event_name == 'workflow_dispatch' |
| 24 | + run: | |
| 25 | + if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 26 | + echo "Error: Version must be in format X.Y.Z.N (e.g., 8.0.0.1)" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +
|
| 30 | + - uses: actions/checkout@v6 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - uses: actions/setup-go@v6 |
| 35 | + with: |
| 36 | + go-version: '1.24' |
| 37 | + cache: true |
| 38 | + |
| 39 | + - name: Verify module builds |
| 40 | + run: go build -v ./... |
| 41 | + |
| 42 | + - name: Run tests |
| 43 | + run: | |
| 44 | + go run ./cmd/download-lib/ |
| 45 | + go test -v ./... |
| 46 | +
|
| 47 | + - name: Create tag (workflow_dispatch only) |
| 48 | + if: github.event_name == 'workflow_dispatch' |
| 49 | + run: | |
| 50 | + git config user.name "github-actions[bot]" |
| 51 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | + # Go modules require v prefix for version tags |
| 53 | + git tag -a "v${{ inputs.version }}" -m "Release ${{ inputs.version }}" |
| 54 | + git push origin "v${{ inputs.version }}" |
| 55 | +
|
| 56 | + - name: Determine version |
| 57 | + id: version |
| 58 | + run: | |
| 59 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 60 | + echo "version=v${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 61 | + echo "display_version=${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 62 | + else |
| 63 | + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 64 | + echo "display_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Generate changelog |
| 68 | + id: changelog |
| 69 | + run: | |
| 70 | + VERSION="${{ steps.version.outputs.version }}" |
| 71 | + DISPLAY_VERSION="${{ steps.version.outputs.display_version }}" |
| 72 | +
|
| 73 | + # Get previous tag (look for v8.* tags) |
| 74 | + PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || echo "") |
| 75 | +
|
| 76 | + if [ -n "$PREV_TAG" ]; then |
| 77 | + echo "Generating changelog from $PREV_TAG to $VERSION" |
| 78 | + COMMITS=$(git log --pretty=format:"- %s (%h)" "$PREV_TAG"..HEAD --no-merges) |
| 79 | + else |
| 80 | + echo "No previous version tag found, using recent commits" |
| 81 | + COMMITS=$(git log --pretty=format:"- %s (%h)" -20 --no-merges) |
| 82 | + fi |
| 83 | +
|
| 84 | + # Write changelog to file (handles multiline) |
| 85 | + { |
| 86 | + echo "## What's Changed" |
| 87 | + echo "" |
| 88 | + echo "$COMMITS" |
| 89 | + echo "" |
| 90 | + echo "## Installation" |
| 91 | + echo "" |
| 92 | + echo '```bash' |
| 93 | + echo "go get github.com/linuxmatters/ffmpeg-statigo@$VERSION" |
| 94 | + echo '```' |
| 95 | + echo "" |
| 96 | + echo "**Full Changelog**: https://github.com/linuxmatters/ffmpeg-statigo/compare/${PREV_TAG:-main}...$VERSION" |
| 97 | + } > changelog.md |
| 98 | +
|
| 99 | + - name: Create GitHub Release |
| 100 | + uses: softprops/action-gh-release@v2 |
| 101 | + with: |
| 102 | + tag_name: ${{ steps.version.outputs.version }} |
| 103 | + name: ${{ steps.version.outputs.display_version }} |
| 104 | + body_path: changelog.md |
| 105 | + draft: false |
| 106 | + prerelease: false |
0 commit comments