Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/actions_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release GitHub Actions

on:
workflow_dispatch:
inputs:
tag:
description: "Tag for the release"
required: true

permissions:
contents: read

jobs:
release:
permissions:
actions: read
id-token: write
contents: write

uses: step-security/reusable-workflows/.github/workflows/actions_release.yaml@v1
with:
tag: "${{ github.event.inputs.tag }}"
37 changes: 37 additions & 0 deletions .github/workflows/auto_cherry_pick.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Auto Cherry-Pick from Upstream

on:
workflow_run:
workflows: [ "Release GitHub Actions" ]
types:
- completed

workflow_dispatch:
inputs:
base_branch:
description: "Base branch to create the PR against"
required: true
default: "main"
mode:
description: "Run mode: cherry-pick or verify"
required: false
default: "cherry-pick"

pull_request:
types: [ opened, synchronize, labeled ]

permissions:
contents: write
pull-requests: write
packages: read
issues: write

jobs:
cherry-pick:
if: (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch' || contains(fromJson(toJson(github.event.pull_request.labels)).*.name, 'review-required')
uses: step-security/reusable-workflows/.github/workflows/auto_cherry_pick.yaml@v1
with:
original-owner: "cygnetdigital"
repo-name: "wait_for_response"
base_branch: ${{ inputs.base_branch || 'main' }}
mode: ${{ github.event_name == 'pull_request' && 'verify' || inputs.mode || 'cherry-pick' }}
55 changes: 55 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish docker image

on:
workflow_dispatch:
inputs:
release_tag:
description: 'Tag to release'
required: true
type: string

permissions:
contents: read
packages: write

jobs:
build:
runs-on: ubuntu-latest
if: startsWith(github.event.inputs.release_tag, 'v')
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@v2
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@v6
- name: Validate tag format
run: |
TAG=${{ github.event.inputs.release_tag }}
if ! echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "❌ Invalid tag format: $TAG"
exit 1
fi
echo "✅ Valid semver tag: $TAG"
- name: Log in to GitHub Container Registry
uses: step-security/docker-login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU for ARM builds
uses: step-security/setup-qemu-action@v4

- name: Set up Docker Buildx
uses: step-security/setup-buildx-action@v4

- name: Build and push Docker image
uses: step-security/docker-build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}:${{ github.event.inputs.release_tag }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Build the app
FROM golang:1.27 as builder
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
WORKDIR /app
# Enable go modules even inside GOPATH
ENV GO111MODULE=on
# Mark neecosem modules as private
# RUN go env -w GOPRIVATE=github.com/newcosem/*

# Copy `go.mod` for definitions and `go.sum` to invalidate the next layer
# in case of a change in the dependencies
#COPY go.mod go.sum ./
# Download dependencies
#RUN go mod download

COPY ./ ./
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test ./...
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o wait_for_response /app/main/main.go

# Create a minimal docker container and copy the app into it
FROM alpine:3.24
RUN apk --no-cache add ca-certificates
WORKDIR /app
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
COPY --from=builder /app/wait_for_response .
RUN chmod +x /app/wait_for_response
ENTRYPOINT ["/app/wait_for_response"]
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2020 Justin Knight
Copyright (c) 2026 StepSecurity

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# wait_for_response
[![StepSecurity Maintained Action](https://raw.githubusercontent.com/step-security/maintained-actions-assets/main/assets/maintained-action-banner.png)](https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions)

# Wait For Response docker action

This action makes a HEAD requests to a given URL until the required response code is retrieved or the timeout is met. Initially created to allow test containers to startup before executing tests against them.

## Inputs

### `url`

The URL to poll. Default `"http://localhost/"`

### `responseCode`

Response code to wait for. Default `"200"`

### `timeout`

Timeout before giving up in milliseconds. Default `"30000"`

### `interval`

Interval between polling in ms. Default `"200"`
default: 200

## Example usage

```
uses: step-security/wait_for_response@v2
with:
url: 'http://localhost:8081/'
responseCode: '200,500'
timeout: 2000
interval: 500
```
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

## Reporting a Vulnerability

Please report security vulnerabilities to security@stepsecurity.io
36 changes: 36 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# action.yml
name: "Wait For HTTP Responses"
author: 'step-security'
branding:
icon: "clock"
color: "blue"
description: "Wait for response code from a URL with timeout"
inputs:
url:
description: "URL to poll"
required: false
default: "http://localhost/"
responseCode:
description: "Response code to wait for"
required: false
default: "200"
timeout:
description: "Timeout before giving up in ms"
required: false
default: "30000"
interval:
description: "Interval between polling in ms"
required: false
default: "200"
username:
description: "Basic Auth Username"
required: false
password:
description: "Basic Auth Password"
required: false
outputs:
result:
description: "0 if response code returned within timeout, otherwise 1"
runs:
using: "docker"
image: "Dockerfile"
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/step-security/wait_for_response

go 1.27
134 changes: 134 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"slices"
"strconv"
"strings"
"time"
)

func validateSubscription() {
var repoPrivate *bool
if eventPath := os.Getenv("GITHUB_EVENT_PATH"); eventPath != "" {
if data, err := os.ReadFile(eventPath); err == nil {
var event struct {
Repository struct {
Private *bool `json:"private"`
} `json:"repository"`
}
if json.Unmarshal(data, &event) == nil {
repoPrivate = event.Repository.Private
}
}
}

upstream := "cygnetdigital/wait_for_response"
action := os.Getenv("GITHUB_ACTION_REPOSITORY")
docsURL := "https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions"

fmt.Println("")
fmt.Println("\u001b[1;36mStepSecurity Maintained Action\u001b[0m")
fmt.Printf("Secure drop-in replacement for %s\n", upstream)
if repoPrivate != nil && !*repoPrivate {
fmt.Println("\u001b[32m\u2713 Free for public repositories\u001b[0m")
}
fmt.Printf("\u001b[36mLearn more:\u001b[0m %s\n", docsURL)
fmt.Println("")

if repoPrivate != nil && !*repoPrivate {
return
}

serverURL := os.Getenv("GITHUB_SERVER_URL")
if serverURL == "" {
serverURL = "https://github.com"
}
body := map[string]string{"action": action}
if serverURL != "https://github.com" {
body["ghes_server"] = serverURL
}
payload, _ := json.Marshal(body)

apiURL := fmt.Sprintf("https://agent.api.stepsecurity.io/v1/github/%s/actions/maintained-actions-subscription", os.Getenv("GITHUB_REPOSITORY"))
client := &http.Client{Timeout: 3 * time.Second}
resp, err := client.Post(apiURL, "application/json", bytes.NewReader(payload))
if err != nil {
fmt.Println("Timeout or API not reachable. Continuing to next step.")
return
}
defer func() {
_ = resp.Body.Close()
}()

if resp.StatusCode == http.StatusForbidden {
fmt.Printf("::error::\u001b[1;31mThis action requires a StepSecurity subscription for private repositories.\u001b[0m\n")
fmt.Printf("::error::\u001b[31mLearn how to enable a subscription: %s\u001b[0m\n", docsURL)
os.Exit(1)
}
}

func main() {
validateSubscription()

url := os.Getenv("INPUT_URL")
responseCode := os.Getenv("INPUT_RESPONSECODE")
timeout, err := strconv.Atoi(os.Getenv("INPUT_TIMEOUT"))
if err != nil {
fmt.Println("Timeout must be an integer")
os.Exit(1)
}
interval, err := strconv.Atoi(os.Getenv("INPUT_INTERVAL"))
if err != nil {
fmt.Println("Interval must be an integer")
os.Exit(1)
}
localhost := os.Getenv("INPUT_LOCALHOST")

username := os.Getenv("INPUT_USERNAME")
password := os.Getenv("INPUT_PASSWORD")

fmt.Printf("Polling URL `%s` for response code %s for up to %d ms at %d ms intervals\n", url, responseCode, timeout, interval)
startTime := time.Now()
timeoutDuration := time.Duration(timeout) * time.Millisecond
sleepDuration := time.Duration(interval) * time.Millisecond

if localhost != "" && strings.Contains(url, "localhost") {
url = strings.ReplaceAll(url, "localhost", localhost)
}

client := &http.Client{}
req, err := http.NewRequest("HEAD", url, nil)
if err != nil {
fmt.Printf("Request Construction: %v\n", err)
os.Exit(1)
}
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved

if username != "" && password != "" {
req.SetBasicAuth(username, password)
}

codes := strings.Split(responseCode, ",")

for {
res, err := client.Do(req)
if err == nil {
code := res.StatusCode
_ = res.Body.Close()
if slices.Contains(codes, strconv.Itoa(code)) {
fmt.Printf("Received expected response code: %d\n", code)
os.Exit(0)
}
}
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
Comment thread
anurag-stepsecurity marked this conversation as resolved.
Resolved
time.Sleep(sleepDuration)
elapsed := time.Since(startTime)
if elapsed > timeoutDuration {
fmt.Printf("Timed out\n")
os.Exit(1)
}
}
}
Loading