diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 427ad25..6b3bdf2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -11,7 +11,7 @@ on: - main jobs: - build_service: + build: name: Build promgithub runs-on: ubuntu-24.04 @@ -24,6 +24,9 @@ jobs: go-version: 1.22.5 id: go + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build run: make build @@ -39,15 +42,5 @@ jobs: # with: # version: v1.50.1 - build_container: - name: Build promgithub Container - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build and push run: make container \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ad58855 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,47 @@ +name: Release promgithub + +on: + push: + branches: + - main + paths: + - 'version' + +env: + REGISTRY: ghcr.io + USERNAME: darthfork + +permissions: + contents: write + packages: write + issues: write + +jobs: + release: + name: Release promgithub + runs-on: ubuntu-24.04 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Golang + uses: actions/setup-go@v5 + with: + go-version: 1.22.5 + id: go + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.USERNAME }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make release diff --git a/Makefile b/Makefile index d4d9093..f9c9de0 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,16 @@ include version -.DEFAULT_GOAL := help +.DEFAULT_GOAL := help TARGET := promgithub -SRC := ./... +SRC := ./... LDFLAGS := -X main.Version=$(VERSION) -s -w LDFLAGS_DBG := -X main.Version=$(VERSION) BUILDDIR := build -REGISTRY := ghcr.io/darthfork +REGISTRY := ghcr.io/darthfork/promgithub help: - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}' + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' mkdir: @mkdir -p $(BUILDDIR) @@ -26,13 +26,30 @@ debug: LDFLAGS := $(LDFLAGS_DBG) debug: TARGET := $(TARGET)-debug debug: all -container: ## Build promgithub service container - @docker build --progress=plain -t $(REGISTRY)/$(TARGET):$(VERSION) . +build-container: ## Build promgithub service container + @docker build --progress=plain -t $(REGISTRY):$(VERSION) . + +push-container: ## Push promgithub service container +push-container: build-container + @docker push $(REGISTRY):$(VERSION) test: GITHUB_WEBHOOK_SECRET := test-secret test: ## Run unit tests @go test -v $(SRC) +cross-platform: ## Create cross-platform binaries +cross-platform: mkdir + GOOS=linux GOARCH=amd64 $(MAKE) TARGET=$(TARGET)-linux-amd64-$(VERSION) build + GOOS=linux GOARCH=arm64 $(MAKE) TARGET=$(TARGET)-linux-arm64-$(VERSION) build + +release: ## Create github release and upload artifacts +release: cross-platform push-container + @gh release create v$(VERSION)\ + --title "promgithub release v$(VERSION)"\ + --generate-notes\ + $(BUILDDIR)/* + + coverage: ## Run unit tests with coverage @go test -cover -v $(SRC) -coverprofile=coverage.out @go tool cover -html=coverage.out diff --git a/utils/create_release.sh b/utils/create_release.sh new file mode 100755 index 0000000..5eebac7 --- /dev/null +++ b/utils/create_release.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +OWNER="darthfork" +REPO="promgithub" +RELEASE_NAME="Release v$VERSION" +RELEASE_DESCRIPTION="Description of the release" +ARTIFACTS=(./build/*) + +#GITHUB_API="https://api.github.com" +# +## Create a release +#echo "Creating a new GitHub release..." +#response=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ +# -H "Accept: application/vnd.github+json" \ +# -d "{ +# \"tag_name\": \"$VERSION\", +# \"name\": \"$RELEASE_NAME\", +# \"body\": \"$RELEASE_DESCRIPTION\", +# \"draft\": false, +# \"prerelease\": false +# }" \ +# "$GITHUB_API/repos/$OWNER/$REPO/releases") +# +## Extract the release ID and upload URL +#release_id=$(echo "$response" | jq -r .id) +#upload_url=$(echo "$response" | jq -r .upload_url | sed -e "s/{?name,label}//") +# +## Check if the release was created successfully +#if [ "$release_id" == "null" ]; then +# echo "Failed to create release. Response:" +# echo "$response" +# exit 1 +#else +# echo "Release created with ID: $release_id" +#fi +# +## Upload each artifact +#for ARTIFACT_PATH in "${ARTIFACTS[@]}"; do +# if [ -f "$ARTIFACT_PATH" ]; then +# echo "Uploading artifact: $ARTIFACT_PATH..." +# artifact_name=$(basename "$ARTIFACT_PATH") +# +# curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ +# -H "Content-Type: application/zip" \ +# --data-binary @"$ARTIFACT_PATH" \ +# "$upload_url?name=$artifact_name" +# +# if [ $? -eq 0 ]; then +# echo "Artifact $artifact_name uploaded successfully!" +# else +# echo "Failed to upload artifact $artifact_name." +# fi +# else +# echo "File $ARTIFACT_PATH does not exist, skipping." +# fi +#done diff --git a/version b/version index b6b0762..73fae53 100644 --- a/version +++ b/version @@ -1,3 +1,3 @@ #!/usr/bin/env make -VERSION = 0.0.1 \ No newline at end of file +VERSION=0.0.1-a