update: action #28
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: Build and Release Go Project | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| jobs: | |
| version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out the code | |
| uses: actions/checkout@v4 | |
| - name: Generate Release Tag | |
| id: generate_tag | |
| run: | | |
| VERSION_TAG="v$(date +'%Y%m%d-%H%M%S')-$(git rev-parse --short HEAD)" | |
| echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV | |
| echo "Generated tag: $VERSION_TAG" | |
| echo "$VERSION_TAG" > VERSION | |
| - name: Upload VERSION Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: VERSION | |
| path: VERSION | |
| build: | |
| needs: version | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64] | |
| steps: | |
| - name: Check out the code | |
| uses: actions/checkout@v4 | |
| - name: Download VERSION Tag | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: VERSION | |
| - name: Set TAG_NAME environment variable | |
| run: | | |
| TAG_NAME=$(cat VERSION) | |
| echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
| echo "Using tag: $TAG_NAME" | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22' | |
| - name: Install dependencies | |
| run: go mod tidy | |
| - name: Build the Go application | |
| run: | | |
| GOARCH=${{ matrix.arch }} go build -ldflags "-X main.version=${{ env.TAG_NAME }}" -o docker-compose-exec-${{ matrix.arch }} | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docker-compose-exec-${{ matrix.arch }} | |
| path: docker-compose-exec-${{ matrix.arch }} | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out the code | |
| uses: actions/checkout@v4 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: docker-compose-exec-amd64 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: docker-compose-exec-arm64 | |
| - name: Download VERSION Tag | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: VERSION | |
| - name: Set TAG_NAME environment variable | |
| run: | | |
| TAG_NAME=$(cat VERSION) | |
| echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
| echo "Using tag: $TAG_NAME" | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| with: | |
| tag_name: ${{ env.TAG_NAME }} | |
| release_name: Release ${{ env.TAG_NAME }} | |
| draft: false | |
| prerelease: false | |
| - name: Upload Release Asset for amd64 | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./docker-compose-exec-amd64 | |
| asset_name: docker-compose-exec-amd64 | |
| asset_content_type: application/octet-stream | |
| - name: Upload Release Asset for arm64 | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./docker-compose-exec-arm64 | |
| asset_name: docker-compose-exec-arm64 | |
| asset_content_type: application/octet-stream |