fix: make TestLockPortSameDirectory_NoError resilient to busy ports #178
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main, master] | |
| pull_request: | |
| branches: [main, master] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.txt ./... | |
| - name: Check formatting | |
| run: | | |
| if [ -n "$(gofmt -l .)" ]; then | |
| echo "Code is not formatted. Run 'go fmt ./...'" | |
| gofmt -d . | |
| exit 1 | |
| fi | |
| - name: Build | |
| env: | |
| CGO_ENABLED: 0 | |
| run: | | |
| VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev") | |
| go build -ldflags "-s -w -X main.version=$VERSION" -o port-selector ./cmd/port-selector | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: golangci-lint | |
| uses: golangci/golangci-lint-action@v4 | |
| with: | |
| version: latest | |
| integration: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Build | |
| env: | |
| CGO_ENABLED: 0 | |
| run: | | |
| VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev") | |
| go build -ldflags "-s -w -X main.version=$VERSION" -o port-selector ./cmd/port-selector | |
| - name: Integration test | |
| run: ./scripts/ci/integration_test.sh "$PWD/port-selector" | |
| test-install-one-liner: | |
| # Only run on master/main branches where install.sh and releases exist | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - name: Test real one-liner install from README | |
| run: curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/install.sh | sh | |
| - name: Verify installation | |
| run: | | |
| # Check binary was installed | |
| if [ ! -f ~/.local/bin/port-selector ]; then | |
| echo "ERROR: port-selector was not installed" | |
| ls -la ~/.local/bin/ 2>/dev/null || echo "Directory doesn't exist" | |
| exit 1 | |
| fi | |
| - name: Check binary is executable | |
| run: | | |
| if [ ! -x ~/.local/bin/port-selector ]; then | |
| echo "ERROR: port-selector is not executable" | |
| ls -la ~/.local/bin/port-selector | |
| exit 1 | |
| fi | |
| - name: Test binary works | |
| run: | | |
| ~/.local/bin/port-selector --help > /dev/null | |
| ~/.local/bin/port-selector --version || true | |
| echo "✅ One-liner install works correctly!" | |
| - name: Test with custom INSTALL_DIR | |
| run: | | |
| TMPDIR=$(mktemp -d) | |
| cd "$TMPDIR" | |
| export INSTALL_DIR="$TMPDIR/bin" | |
| curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/install.sh | sh | |
| if [ ! -f "$INSTALL_DIR/port-selector" ]; then | |
| echo "ERROR: Custom INSTALL_DIR failed" | |
| exit 1 | |
| fi | |
| echo "✅ Custom INSTALL_DIR works!" | |
| - name: Test with VERSION parameter | |
| run: | | |
| # Test that VERSION parameter is accepted (may fail if version doesn't exist) | |
| TMPDIR=$(mktemp -d) | |
| cd "$TMPDIR" | |
| export INSTALL_DIR="$TMPDIR/bin" | |
| export VERSION=v0.8.0 | |
| if curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/${{ github.ref_name }}/install.sh | sh 2>/dev/null; then | |
| echo "✅ VERSION parameter works" | |
| else | |
| echo "Note: v0.8.0 may not exist, but parameter was accepted" | |
| fi | |
| install-test: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Test one-liner install script (dry run) | |
| run: | | |
| # Test that the install script syntax is valid | |
| sh -n ./install.sh | |
| # Test basic installation flow with latest version | |
| # We can't test the actual download from GitHub in PRs easily, | |
| # but we can test the script logic with VERSION=latest | |
| echo "Testing install script with VERSION=latest" | |
| # This will fail on download but we can check script logic | |
| # by running it in a subshell and checking for proper error handling | |
| # Create a temp directory for testing | |
| TMPDIR=$(mktemp -d) | |
| cd "$TMPDIR" | |
| # Test 1: Basic install defaults | |
| echo "Test 1: Check install script accepts VERSION=latest" | |
| if ! bash -c 'VERSION=latest DRYRUN=yes bash $GITHUB_WORKSPACE/install.sh' 2>/dev/null; then | |
| # Expected to fail on actual download in PR, but that's ok | |
| echo "Script executed (download expected to fail in PR)" | |
| fi | |
| # Test 2: Custom INSTALL_DIR | |
| echo "Test 2: Check INSTALL_DIR variable works" | |
| TEST_DIR="$TMPDIR/test-install" | |
| export VERSION=latest | |
| export INSTALL_DIR="$TEST_DIR" | |
| # Just check the script doesn't have syntax errors and accepts variables | |
| bash -n $GITHUB_WORKSPACE/install.sh | |
| echo "Script accepts INSTALL_DIR parameter" | |
| # Test 3: Check different VERSION format | |
| echo "Test 3: Check VERSION=v0.8.0 format" | |
| export VERSION=v0.8.0 | |
| bash -n $GITHUB_WORKSPACE/install.sh | |
| echo "Script accepts VERSION parameter" | |
| # Cleanup | |
| rm -rf "$TMPDIR" |