Skip to content

Add cross-platform support for Windows and macOS runners #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).

Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 16 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
68 changes: 68 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -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"