fix: use Go 1.22 for GitHub Actions compatibility #9
Workflow file for this run
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: | |
| tags: | |
| - 'v*.*.*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version (e.g., 1.2.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| name: Build Binaries | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - goos: linux | |
| goarch: amd64 | |
| - goos: linux | |
| goarch: arm64 | |
| - goos: darwin | |
| goarch: amd64 | |
| - goos: darwin | |
| goarch: arm64 | |
| - goos: windows | |
| goarch: amd64 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Extract version | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| - name: Download dependencies | |
| run: | | |
| go mod download | |
| go mod verify | |
| - name: Build | |
| run: | | |
| set -e | |
| BINARY_NAME=doplan | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| BINARY_NAME=doplan.exe | |
| fi | |
| echo "Building for ${{ matrix.goos }}/${{ matrix.goarch }}..." | |
| echo "Go version: $(go version)" | |
| echo "Module path: $(go list -m)" | |
| GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -v -ldflags "-X github.com/doplan/cli/internal/version.Version=${{ steps.version.outputs.version }}" -o $BINARY_NAME ./cmd/doplan | |
| ls -lh $BINARY_NAME || echo "Binary not created!" | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| - name: Create archive | |
| run: | | |
| VERSION=${{ steps.version.outputs.version }} | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| zip doplan-$VERSION-${{ matrix.goos }}-${{ matrix.goarch }}.zip doplan.exe | |
| sha256sum doplan-$VERSION-${{ matrix.goos }}-${{ matrix.goarch }}.zip > doplan-$VERSION-${{ matrix.goos }}-${{ matrix.goarch }}.zip.sha256 | |
| else | |
| tar -czf doplan-$VERSION-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz doplan | |
| sha256sum doplan-$VERSION-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz > doplan-$VERSION-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz.sha256 | |
| fi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: doplan-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: | | |
| doplan-*-${{ matrix.goos }}-${{ matrix.goarch }}.* | |
| doplan* | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| check-latest: true | |
| - name: Extract version | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| else | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | |
| - name: Update package.json version | |
| run: | | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| TARGET_VERSION="${{ steps.get_version.outputs.version }}" | |
| if [ "$CURRENT_VERSION" != "$TARGET_VERSION" ]; then | |
| npm version $TARGET_VERSION --no-git-tag-version | |
| else | |
| echo "Version already set to $TARGET_VERSION, skipping update" | |
| fi | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| - name: Generate release notes | |
| id: release_notes | |
| run: | | |
| if [ -f CHANGELOG.md ]; then | |
| # Extract changelog section for this version | |
| VERSION="${{ steps.get_version.outputs.version }}" | |
| awk "/^## \\[$VERSION\\]/,/^## /" CHANGELOG.md | head -n -1 > release_notes.txt || true | |
| else | |
| echo "No CHANGELOG.md found" > release_notes.txt | |
| fi | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.get_version.outputs.tag }} | |
| name: Release ${{ steps.get_version.outputs.tag }} | |
| body_path: release_notes.txt | |
| files: dist/**/* | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Commit version bump | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add package.json | |
| git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" || exit 0 | |
| git push || exit 0 |