From 2cd9138424466fd9bd5b2ed074cdd74c482d4c00 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Jul 2025 13:27:32 +0000 Subject: [PATCH 1/2] Initial plan From 45bac500433f51ebb9cd413e484b033bc44a1d4e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 17 Jul 2025 13:34:24 +0000 Subject: [PATCH 2/2] Implement cross-platform compatibility using composite action with Docker wrapper Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com> --- README.md | 37 +++++++++++++++++++++++++++++ action.yml | 20 ++++++++++++---- run.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 4 deletions(-) create mode 100755 run.sh diff --git a/README.md b/README.md index 2c2d6ab..92bb990 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # GitHub Action for committing changes to a repository. ### Supporting `amd64` and `aarch64/arm64` images! +### **Cross-platform compatible** - Works on Linux, Windows, and macOS runners! Useful in combination with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request). @@ -10,6 +11,7 @@ And GitHub Packages: [ghcr.io/devops-infra/action-commit-push/action-commit-push Features: +* **Cross-platform support** - Works on Linux, Windows (with Docker Desktop), and macOS runners. * Can add a custom prefix to commit message title by setting `commit_prefix`. * As a commit message title will use `commit_message` if set, or `commit_prefix` and add changed files or just list of changed files. * Can create a new branch when `target_branch` is set. @@ -71,6 +73,41 @@ Features: | branch_name | Name of the branch code was pushed into. | +## Platform Requirements + +This action now supports **cross-platform execution**: + +- **Linux runners**: Fully supported (default GitHub Actions environment) +- **Windows runners**: Requires Docker to be installed (e.g., Docker Desktop, Rancher Desktop) +- **macOS runners**: Requires Docker to be installed + +### Windows Runner Setup + +To use this action on Windows runners, ensure Docker is available: + +```yaml +jobs: + commit-changes: + runs-on: windows-latest + steps: + - name: Setup Docker (if needed) + # Most GitHub-hosted Windows runners have Docker pre-installed + # For self-hosted runners, ensure Docker Desktop is installed + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Commit and push changes + uses: devops-infra/action-commit-push@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + commit_message: "Cross-platform commit from Windows" +``` + +### Note +The action automatically detects the platform and uses Docker accordingly. On all platforms, it runs the same containerized environment to ensure consistent behavior. + + ## Examples Commit and push changes to currently checked out branch. diff --git a/action.yml b/action.yml index 90c4ae9..329a39d 100644 --- a/action.yml +++ b/action.yml @@ -48,10 +48,22 @@ outputs: branch_name: description: Name of the branch code was pushed into runs: - using: docker - image: docker://devopsinfra/action-commit-push:v0.10.0 - env: - GITHUB_TOKEN: ${{ inputs.github_token }} + using: composite + steps: + - name: Run action + run: ${{ github.action_path }}/run.sh + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github_token }} + INPUT_ADD_TIMESTAMP: ${{ inputs.add_timestamp }} + INPUT_AMEND: ${{ inputs.amend }} + INPUT_COMMIT_PREFIX: ${{ inputs.commit_prefix }} + INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }} + INPUT_FORCE: ${{ inputs.force }} + INPUT_FORCE_WITHOUT_LEASE: ${{ inputs.force_without_lease }} + INPUT_NO_EDIT: ${{ inputs.no_edit }} + INPUT_ORGANIZATION_DOMAIN: ${{ inputs.organization_domain }} + INPUT_TARGET_BRANCH: ${{ inputs.target_branch }} branding: color: purple icon: upload-cloud diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..451fb79 --- /dev/null +++ b/run.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +set -e + +# Detect the operating system +OS_TYPE="$(uname -s)" +echo "Running on OS: $OS_TYPE" + +# Check if Docker is available +if ! command -v docker &> /dev/null; then + echo "Error: Docker is not available. This action requires Docker to be installed." + echo "On Windows runners, please ensure Docker Desktop or similar is installed." + echo "On Linux/macOS runners, Docker should be available by default." + exit 1 +fi + +# Docker image to use +DOCKER_IMAGE="docker://devopsinfra/action-commit-push:v0.10.0" + +# Prepare environment variables for docker run +ENV_ARGS=() +ENV_ARGS+=("-e" "GITHUB_TOKEN=${GITHUB_TOKEN}") +ENV_ARGS+=("-e" "GITHUB_ACTOR=${GITHUB_ACTOR}") +ENV_ARGS+=("-e" "GITHUB_REPOSITORY=${GITHUB_REPOSITORY}") +ENV_ARGS+=("-e" "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}") +ENV_ARGS+=("-e" "GITHUB_OUTPUT=${GITHUB_OUTPUT}") + +# Add input environment variables +ENV_ARGS+=("-e" "INPUT_ADD_TIMESTAMP=${INPUT_ADD_TIMESTAMP}") +ENV_ARGS+=("-e" "INPUT_AMEND=${INPUT_AMEND}") +ENV_ARGS+=("-e" "INPUT_COMMIT_PREFIX=${INPUT_COMMIT_PREFIX}") +ENV_ARGS+=("-e" "INPUT_COMMIT_MESSAGE=${INPUT_COMMIT_MESSAGE}") +ENV_ARGS+=("-e" "INPUT_FORCE=${INPUT_FORCE}") +ENV_ARGS+=("-e" "INPUT_FORCE_WITHOUT_LEASE=${INPUT_FORCE_WITHOUT_LEASE}") +ENV_ARGS+=("-e" "INPUT_NO_EDIT=${INPUT_NO_EDIT}") +ENV_ARGS+=("-e" "INPUT_ORGANIZATION_DOMAIN=${INPUT_ORGANIZATION_DOMAIN}") +ENV_ARGS+=("-e" "INPUT_TARGET_BRANCH=${INPUT_TARGET_BRANCH}") + +# Volume mount arguments +VOLUME_ARGS=() +VOLUME_ARGS+=("-v" "${GITHUB_WORKSPACE}:/github/workspace") + +# Working directory +WORK_DIR="/github/workspace" + +# Remove docker:// prefix from image name if present +DOCKER_IMAGE_NAME="${DOCKER_IMAGE#docker://}" + +echo "Using Docker image: $DOCKER_IMAGE_NAME" +echo "Workspace: $GITHUB_WORKSPACE" + +# Attempt to pull the image if it doesn't exist locally +if ! docker image inspect "$DOCKER_IMAGE_NAME" &> /dev/null; then + echo "Docker image not found locally, attempting to pull: $DOCKER_IMAGE_NAME" + if ! docker pull "$DOCKER_IMAGE_NAME"; then + echo "Error: Failed to pull Docker image: $DOCKER_IMAGE_NAME" + echo "Please ensure the image exists and is accessible." + exit 1 + fi +fi + +# Run the Docker container +echo "Running Docker container..." +docker run --rm \ + "${ENV_ARGS[@]}" \ + "${VOLUME_ARGS[@]}" \ + -w "$WORK_DIR" \ + "$DOCKER_IMAGE_NAME" \ No newline at end of file