Skip to content

Commit 45bac50

Browse files
Implement cross-platform compatibility using composite action with Docker wrapper
Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
1 parent 2cd9138 commit 45bac50

File tree

3 files changed

+121
-4
lines changed

3 files changed

+121
-4
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# GitHub Action for committing changes to a repository.
22

33
### Supporting `amd64` and `aarch64/arm64` images!
4+
### **Cross-platform compatible** - Works on Linux, Windows, and macOS runners!
45

56
Useful in combination with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
67

@@ -10,6 +11,7 @@ And GitHub Packages: [ghcr.io/devops-infra/action-commit-push/action-commit-push
1011

1112

1213
Features:
14+
* **Cross-platform support** - Works on Linux, Windows (with Docker Desktop), and macOS runners.
1315
* Can add a custom prefix to commit message title by setting `commit_prefix`.
1416
* As a commit message title will use `commit_message` if set, or `commit_prefix` and add changed files or just list of changed files.
1517
* Can create a new branch when `target_branch` is set.
@@ -71,6 +73,41 @@ Features:
7173
| branch_name | Name of the branch code was pushed into. |
7274

7375

76+
## Platform Requirements
77+
78+
This action now supports **cross-platform execution**:
79+
80+
- **Linux runners**: Fully supported (default GitHub Actions environment)
81+
- **Windows runners**: Requires Docker to be installed (e.g., Docker Desktop, Rancher Desktop)
82+
- **macOS runners**: Requires Docker to be installed
83+
84+
### Windows Runner Setup
85+
86+
To use this action on Windows runners, ensure Docker is available:
87+
88+
```yaml
89+
jobs:
90+
commit-changes:
91+
runs-on: windows-latest
92+
steps:
93+
- name: Setup Docker (if needed)
94+
# Most GitHub-hosted Windows runners have Docker pre-installed
95+
# For self-hosted runners, ensure Docker Desktop is installed
96+
97+
- name: Checkout repository
98+
uses: actions/checkout@v4
99+
100+
- name: Commit and push changes
101+
uses: devops-infra/action-commit-push@master
102+
with:
103+
github_token: ${{ secrets.GITHUB_TOKEN }}
104+
commit_message: "Cross-platform commit from Windows"
105+
```
106+
107+
### Note
108+
The action automatically detects the platform and uses Docker accordingly. On all platforms, it runs the same containerized environment to ensure consistent behavior.
109+
110+
74111
## Examples
75112

76113
Commit and push changes to currently checked out branch.

action.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,22 @@ outputs:
4848
branch_name:
4949
description: Name of the branch code was pushed into
5050
runs:
51-
using: docker
52-
image: docker://devopsinfra/action-commit-push:v0.10.0
53-
env:
54-
GITHUB_TOKEN: ${{ inputs.github_token }}
51+
using: composite
52+
steps:
53+
- name: Run action
54+
run: ${{ github.action_path }}/run.sh
55+
shell: bash
56+
env:
57+
GITHUB_TOKEN: ${{ inputs.github_token }}
58+
INPUT_ADD_TIMESTAMP: ${{ inputs.add_timestamp }}
59+
INPUT_AMEND: ${{ inputs.amend }}
60+
INPUT_COMMIT_PREFIX: ${{ inputs.commit_prefix }}
61+
INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }}
62+
INPUT_FORCE: ${{ inputs.force }}
63+
INPUT_FORCE_WITHOUT_LEASE: ${{ inputs.force_without_lease }}
64+
INPUT_NO_EDIT: ${{ inputs.no_edit }}
65+
INPUT_ORGANIZATION_DOMAIN: ${{ inputs.organization_domain }}
66+
INPUT_TARGET_BRANCH: ${{ inputs.target_branch }}
5567
branding:
5668
color: purple
5769
icon: upload-cloud

run.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Detect the operating system
6+
OS_TYPE="$(uname -s)"
7+
echo "Running on OS: $OS_TYPE"
8+
9+
# Check if Docker is available
10+
if ! command -v docker &> /dev/null; then
11+
echo "Error: Docker is not available. This action requires Docker to be installed."
12+
echo "On Windows runners, please ensure Docker Desktop or similar is installed."
13+
echo "On Linux/macOS runners, Docker should be available by default."
14+
exit 1
15+
fi
16+
17+
# Docker image to use
18+
DOCKER_IMAGE="docker://devopsinfra/action-commit-push:v0.10.0"
19+
20+
# Prepare environment variables for docker run
21+
ENV_ARGS=()
22+
ENV_ARGS+=("-e" "GITHUB_TOKEN=${GITHUB_TOKEN}")
23+
ENV_ARGS+=("-e" "GITHUB_ACTOR=${GITHUB_ACTOR}")
24+
ENV_ARGS+=("-e" "GITHUB_REPOSITORY=${GITHUB_REPOSITORY}")
25+
ENV_ARGS+=("-e" "GITHUB_WORKSPACE=${GITHUB_WORKSPACE}")
26+
ENV_ARGS+=("-e" "GITHUB_OUTPUT=${GITHUB_OUTPUT}")
27+
28+
# Add input environment variables
29+
ENV_ARGS+=("-e" "INPUT_ADD_TIMESTAMP=${INPUT_ADD_TIMESTAMP}")
30+
ENV_ARGS+=("-e" "INPUT_AMEND=${INPUT_AMEND}")
31+
ENV_ARGS+=("-e" "INPUT_COMMIT_PREFIX=${INPUT_COMMIT_PREFIX}")
32+
ENV_ARGS+=("-e" "INPUT_COMMIT_MESSAGE=${INPUT_COMMIT_MESSAGE}")
33+
ENV_ARGS+=("-e" "INPUT_FORCE=${INPUT_FORCE}")
34+
ENV_ARGS+=("-e" "INPUT_FORCE_WITHOUT_LEASE=${INPUT_FORCE_WITHOUT_LEASE}")
35+
ENV_ARGS+=("-e" "INPUT_NO_EDIT=${INPUT_NO_EDIT}")
36+
ENV_ARGS+=("-e" "INPUT_ORGANIZATION_DOMAIN=${INPUT_ORGANIZATION_DOMAIN}")
37+
ENV_ARGS+=("-e" "INPUT_TARGET_BRANCH=${INPUT_TARGET_BRANCH}")
38+
39+
# Volume mount arguments
40+
VOLUME_ARGS=()
41+
VOLUME_ARGS+=("-v" "${GITHUB_WORKSPACE}:/github/workspace")
42+
43+
# Working directory
44+
WORK_DIR="/github/workspace"
45+
46+
# Remove docker:// prefix from image name if present
47+
DOCKER_IMAGE_NAME="${DOCKER_IMAGE#docker://}"
48+
49+
echo "Using Docker image: $DOCKER_IMAGE_NAME"
50+
echo "Workspace: $GITHUB_WORKSPACE"
51+
52+
# Attempt to pull the image if it doesn't exist locally
53+
if ! docker image inspect "$DOCKER_IMAGE_NAME" &> /dev/null; then
54+
echo "Docker image not found locally, attempting to pull: $DOCKER_IMAGE_NAME"
55+
if ! docker pull "$DOCKER_IMAGE_NAME"; then
56+
echo "Error: Failed to pull Docker image: $DOCKER_IMAGE_NAME"
57+
echo "Please ensure the image exists and is accessible."
58+
exit 1
59+
fi
60+
fi
61+
62+
# Run the Docker container
63+
echo "Running Docker container..."
64+
docker run --rm \
65+
"${ENV_ARGS[@]}" \
66+
"${VOLUME_ARGS[@]}" \
67+
-w "$WORK_DIR" \
68+
"$DOCKER_IMAGE_NAME"

0 commit comments

Comments
 (0)