From 5f4faf74584ed45d70c0a483abf03de794b29b29 Mon Sep 17 00:00:00 2001 From: Lek Huda Date: Thu, 1 Aug 2024 23:12:32 +0700 Subject: [PATCH] fix script exited --- .github/workflows/release.yml | 37 +++++++++++++++++++++++++---------- internal/script/script.go | 14 ++++++++++--- pkg/dockermi.go | 4 ++-- utils/utils.go | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2985472..cf909cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,19 +1,16 @@ name: Build and Release on: - workflow_run: - workflows: ["Go"] # Name of the workflow to listen for - types: - - completed # Trigger this workflow when the Go workflow completes + push: + tags: + - 'v*' # Trigger this workflow for tags like v0.1.0, v0.1.1, etc. jobs: build: - if: ${{ github.event.workflow_run.conclusion == 'success' }} # Only run if the Go workflow succeeded runs-on: ubuntu-latest permissions: contents: write # Required to create a release issues: read # Optional, if you need to read issues - # Add other permissions as needed steps: - name: Checkout @@ -24,9 +21,25 @@ jobs: with: go-version: '1.19' # Set your Go version - - name: Extract version - id: get_version - run: echo "VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV # Extract the tag name correctly + - name: Determine Version + id: determine_version + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + VERSION=${GITHUB_REF##*/} + echo "VERSION=${VERSION}" >> $GITHUB_ENV # Extract the tag name + else + echo "Unrecognized reference, exiting." + exit 1 # Exit if it's neither a tag nor main branch + fi + echo "TAG_URL=https://github.com/${{ github.repository }}/releases/tag/${{ env.VERSION }}" >> $GITHUB_ENV + + - name: Get Previous Tag + id: get_previous_tag + run: | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then + PREVIOUS_TAG=$(git tag --sort=-creatordate | awk -v current="${{ env.VERSION }}" '$0 == current {getline; print; exit}') + echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> $GITHUB_ENV + fi - name: Build for Linux run: | @@ -44,12 +57,16 @@ jobs: zip dockermi-${{ env.VERSION }}.zip dockermi-${{ env.VERSION }}.exe - name: Create Release + if: startsWith(github.ref, 'refs/tags/') # Only create a release if it's a tag uses: softprops/action-gh-release@v1 with: tag_name: ${{ env.VERSION }} # Use the tag extracted earlier + name: Release ${{ env.VERSION }} + body: | + **Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ env.PREVIOUS_TAG }}...${{ env.VERSION }} files: | dockermi-linux-${{ env.VERSION }}.tar.gz dockermi-macos-${{ env.VERSION }}.tar.gz dockermi-${{ env.VERSION }}.zip env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/internal/script/script.go b/internal/script/script.go index 53027ef..c928ed9 100644 --- a/internal/script/script.go +++ b/internal/script/script.go @@ -35,7 +35,7 @@ func CreateDockermiScript(scriptPath string, services DockermiTypes.ServiceScrip for _, service := range services { dockermiScript.WriteString(fmt.Sprintf(" echo \"Starting %s...\"\n", service.ServiceName)) - dockermiScript.WriteString(fmt.Sprintf(" docker-compose -f \"%s\" up \"%s\" \"$@\"\n", service.ComposeFile, service.ServiceName)) // Pass additional options and specify the service name + dockermiScript.WriteString(fmt.Sprintf(" docker-compose -f \"%s\" up -d \"%s\" \"$@\"\n", service.ComposeFile, service.ServiceName)) // Pass additional options and specify the service name color.Cyan("\n Creating script for %v", service.ServiceName) bar.Add(1) @@ -56,8 +56,16 @@ func CreateDockermiScript(scriptPath string, services DockermiTypes.ServiceScrip } dockermiScript.WriteString("}\n\n") - // Add main logic to call the appropriate function based on the argument - dockermiScript.WriteString(`if [ "$#" -lt 1 ]; then + // Add signal trap and main logic to call the appropriate function based on the argument + dockermiScript.WriteString(`cleanup() { + echo "Caught interrupt signal. Stopping services..." + exit 0 +} + +# Register the cleanup function to be called on SIGINT (Ctrl+C) +trap cleanup SIGINT + +if [ "$#" -lt 1 ]; then echo "Invalid argument!" echo "Usage: $0 [up|down] [options]" exit 1 diff --git a/pkg/dockermi.go b/pkg/dockermi.go index fbf70f2..467cd1c 100644 --- a/pkg/dockermi.go +++ b/pkg/dockermi.go @@ -16,7 +16,7 @@ import ( "github.com/fatih/color" ) -const version = "0.1.1" +const version = "0.1.2" // RunDockermi executes the main logic of the dockermi command. It takes a // projectDir parameter, which specifies the directory where the function @@ -69,7 +69,7 @@ func RunDockermi(projectDir string) (string, error) { // handleUpDownCommand handles the 'up' command logic. func handleUpDownCommand(projectDir string, command string, args []string) (string, error) { - color.Green("Executing 'up' command...") + color.Green("Executing %v command...", command) return runDockermiScript(projectDir, command, args) } diff --git a/utils/utils.go b/utils/utils.go index 163857d..c91fe42 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -22,6 +22,6 @@ Options: Examples: dockermi # Generates a dockermi.sh script in the current directory. dockermi create myservicekey # [Experimental] Create a script for the specified service key. - dockermi up --build # Start services with the --build option. + dockermi up -d --build # Start services with the --build option. dockermi down --remove-orphans # Stop services and remove orphan containers.`) }