Merge pull request #7 from RusEu/copilot/fix-download-link-readme #14
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| jobs: | |
| build: | |
| name: Build Binaries | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| include: | |
| - goos: linux | |
| goarch: amd64 | |
| artifact_name: server-admin-bot-linux-amd64 | |
| - goos: linux | |
| goarch: arm64 | |
| artifact_name: server-admin-bot-linux-arm64 | |
| - goos: windows | |
| goarch: amd64 | |
| artifact_name: server-admin-bot-windows-amd64 | |
| - goos: darwin | |
| goarch: amd64 | |
| artifact_name: server-admin-bot-darwin-amd64 | |
| - goos: darwin | |
| goarch: arm64 | |
| artifact_name: server-admin-bot-darwin-arm64 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Get dependencies | |
| run: | | |
| go mod download | |
| go mod verify | |
| - name: Build binary | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| CGO_ENABLED: 0 | |
| run: | | |
| OUTPUT_NAME="${{ matrix.artifact_name }}" | |
| if [ "${{ matrix.goos }}" = "windows" ]; then | |
| OUTPUT_NAME="${OUTPUT_NAME}.exe" | |
| fi | |
| go build -v -ldflags="-s -w -X main.version=${GITHUB_REF_NAME} -X main.buildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ) -X main.gitCommit=${GITHUB_SHA}" -o "${OUTPUT_NAME}" ./cmd/bot/main.go | |
| - name: Create tarball (Unix) | |
| if: matrix.goos != 'windows' | |
| run: | | |
| if [ -f LICENSE ]; then | |
| tar -czf ${{ matrix.artifact_name }}.tar.gz ${{ matrix.artifact_name }} README.md LICENSE | |
| else | |
| tar -czf ${{ matrix.artifact_name }}.tar.gz ${{ matrix.artifact_name }} README.md | |
| fi | |
| - name: Create zip (Windows) | |
| if: matrix.goos == 'windows' | |
| run: | | |
| if [ -f LICENSE ]; then | |
| zip ${{ matrix.artifact_name }}.zip ${{ matrix.artifact_name }}.exe README.md LICENSE | |
| else | |
| zip ${{ matrix.artifact_name }}.zip ${{ matrix.artifact_name }}.exe README.md | |
| fi | |
| - name: Upload artifact (Unix) | |
| if: matrix.goos != 'windows' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact_name }} | |
| path: ${{ matrix.artifact_name }}.tar.gz | |
| retention-days: 30 | |
| - name: Upload artifact (Windows) | |
| if: matrix.goos == 'windows' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact_name }} | |
| path: ${{ matrix.artifact_name }}.zip | |
| retention-days: 30 | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Display structure of downloaded files | |
| run: ls -R artifacts | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| artifacts/server-admin-bot-linux-amd64/server-admin-bot-linux-amd64.tar.gz | |
| artifacts/server-admin-bot-linux-arm64/server-admin-bot-linux-arm64.tar.gz | |
| artifacts/server-admin-bot-windows-amd64/server-admin-bot-windows-amd64.zip | |
| artifacts/server-admin-bot-darwin-amd64/server-admin-bot-darwin-amd64.tar.gz | |
| artifacts/server-admin-bot-darwin-arm64/server-admin-bot-darwin-arm64.tar.gz | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |