Skip to content

Commit

Permalink
fix script exited
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuda committed Aug 1, 2024
1 parent 6aeeb02 commit 5f4faf7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: |
Expand All @@ -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 }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 11 additions & 3 deletions internal/script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/dockermi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
}

0 comments on commit 5f4faf7

Please sign in to comment.