diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a80ffb1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: Release + +on: + release: + types: [created] + +permissions: + contents: write + packages: write + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + goos: [linux, windows, darwin] + goarch: [amd64, arm64] + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + run: | + BINARY_NAME="object-holder" + if [ "$GOOS" = "windows" ]; then + BINARY_NAME="${BINARY_NAME}.exe" + fi + go build -v -o "${BINARY_NAME}" ./... + - name: Create archive + run: | + BINARY_NAME="object-holder" + if [ "${{ matrix.goos }}" = "windows" ]; then + BINARY_NAME="${BINARY_NAME}.exe" + fi + ARCHIVE_NAME="object-holder-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}" + + # Create directory structure + mkdir -p "${ARCHIVE_NAME}" + cp "${BINARY_NAME}" README.md LICENSE "${ARCHIVE_NAME}/" + + if [ "${{ matrix.goos }}" = "windows" ]; then + zip -r "${ARCHIVE_NAME}.zip" "${ARCHIVE_NAME}" + echo "ASSET_PATH=${ARCHIVE_NAME}.zip" >> $GITHUB_ENV + else + tar -czf "${ARCHIVE_NAME}.tar.gz" "${ARCHIVE_NAME}" + echo "ASSET_PATH=${ARCHIVE_NAME}.tar.gz" >> $GITHUB_ENV + fi + - name: Upload release asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ${{ env.ASSET_PATH }} + asset_name: ${{ env.ASSET_PATH }} + asset_content_type: application/octet-stream + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to ghcr + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=tag + type=raw,value=latest + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}