diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 36ce4c3..1f04c8a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -10,58 +10,57 @@ on: - LICENSE jobs: - gettime: + setup: runs-on: ubuntu-latest + env: + GO_VERSION: 1.23.2 outputs: timestamp: ${{ env.TIMESTAMP }} steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Dependencies + run: go mod download + - name: Get current timestamp id: timestamp run: echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV build: runs-on: ubuntu-latest - needs: gettime + needs: setup strategy: matrix: os: [linux, windows, darwin] - go-version: ["1.23.1"] + arch: [amd64, arm64] env: - TIMESTAMP: ${{ needs.gettime.outputs.timestamp }} + TIMESTAMP: ${{ needs.setup.outputs.timestamp }} steps: - uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - name: Build run: | - mkdir -p bin - case ${{ matrix.os }} in - linux) - GOOS=linux GOARCH=amd64 make BINARY_NAME=kthcloud_amd64_linux BUILDTIMESTAMP=${{ env.TIMESTAMP }} ;; - windows) - GOOS=windows GOARCH=amd64 make BINARY_NAME=kthcloud_amd64_windows.exe BUILDTIMESTAMP=${{ env.TIMESTAMP }} ;; - darwin) - GOOS=darwin GOARCH=arm64 make BINARY_NAME=kthcloud_arm64_macos BUILDTIMESTAMP=${{ env.TIMESTAMP }} ;; - esac + GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make release BINARY_NAME=kthcloud_${{ matrix.arch }}_${{ matrix.os }} BUILDTIMESTAMP=${{ env.TIMESTAMP }} - name: Upload Artifacts uses: actions/upload-artifact@v4 with: - name: ${{ matrix.os }}-binaries + name: ${{ matrix.arch }}_${{ matrix.os }}_bins path: bin/* if-no-files-found: error release: needs: - - gettime + - setup - build runs-on: ubuntu-latest env: - TIMESTAMP: ${{ needs.gettime.outputs.timestamp }} + TIMESTAMP: ${{ needs.setup.outputs.timestamp }} outputs: upload_url: ${{ steps.step_upload_url.outputs.upload_url }} steps: @@ -71,11 +70,6 @@ jobs: path: "./artifacts" if-no-files-found: error - - name: Generate SHA512 checksums - run: | - cd artifacts - find . -type f -name 'kthcloud*' -exec sha512sum {} + | sed 's|^\./||' > SHA512SUMS.txt - - name: Create Release id: create_release uses: softprops/action-gh-release@v2 diff --git a/.github/workflows/rc.yml b/.github/workflows/rc.yml new file mode 100644 index 0000000..44fa33e --- /dev/null +++ b/.github/workflows/rc.yml @@ -0,0 +1,55 @@ +name: RC + +on: + push: + branches: ["rc"] + paths-ignore: + - README.md + - .gitignore + #- .github/** + - LICENSE + +jobs: + setup: + runs-on: ubuntu-latest + env: + GO_VERSION: 1.23.2 + outputs: + timestamp: ${{ env.TIMESTAMP }} + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Dependencies + run: go mod download + + - name: Get current timestamp + id: timestamp + run: echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + + build: + runs-on: ubuntu-latest + needs: setup + strategy: + matrix: + os: [linux, windows, darwin] + arch: [amd64, arm64] + env: + TIMESTAMP: ${{ needs.setup.outputs.timestamp }} + steps: + - uses: actions/checkout@v4 + + - name: Build + run: | + GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make release BINARY_NAME=kthcloud_${{ matrix.arch }}_${{ matrix.os }} BUILDTIMESTAMP=${{ env.TIMESTAMP }} + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.arch }}_${{ matrix.os }}_bins + path: bin/* + if-no-files-found: error diff --git a/Makefile b/Makefile index b889638..fcf1b60 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ BINARY_NAME=kthcloud BUILD_DIR=bin MAIN_FILE=main.go BUILDTIMESTAMP=$(shell date -u +%Y%m%d%H%M%S) +EXT=$(if $(filter windows,$(GOOS)),.exe,) # Targets .PHONY: all clean build run @@ -12,19 +13,40 @@ all: build build: @echo "Building the application..." @mkdir -p $(BUILD_DIR) - @CGO_ENABLED=0 go build -ldflags "-X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/$(BINARY_NAME) . + @CGO_ENABLED=0 go build -ldflags "-X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/$(BINARY_NAME)$(EXT) . @echo "Build complete." run: build @echo "Running the application..." - @./$(BUILD_DIR)/$(BINARY_NAME) + @./$(BUILD_DIR)/$(BINARY_NAME)$(EXT) -install: build +test: + @go test ./... + +release: + @echo "Building the application..." + @mkdir -p $(BUILD_DIR) + @CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/$(BINARY_NAME)$(EXT) . + @echo "Build complete." + +install: release @echo "installing" @mkdir -p ~/.local/kthcloud/bin - @cp ./$(BUILD_DIR)/$(BINARY_NAME) ~/.local/kthcloud/bin/$(BINARY_NAME) + @cp ./$(BUILD_DIR)/$(BINARY_NAME)$(EXT) ~/.local/kthcloud/bin/$(BINARY_NAME)$(EXT) @echo "add to PATH" +all-platforms: + @echo "Building for multiple platforms..." + @mkdir -p $(BUILD_DIR) + @GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/kthcloud_amd64_linux . & + @GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/kthcloud_arm64_linux . & + @GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/kthcloud_amd64_windows.exe . & + @GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/kthcloud_arm64_windows.exe . & + @GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/kthcloud_amd64_macos . & + @GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -mod=readonly -ldflags "-w -s -X main.buildTimestamp=$(BUILDTIMESTAMP)" -o $(BUILD_DIR)/kthcloud_arm64_macos . & + @wait + @echo "All builds complete." + clean: @echo "Cleaning up..." @rm -rf $(BUILD_DIR)