From 46d9ebabb44b7ae28d3210416e24e6451e45ddfd Mon Sep 17 00:00:00 2001
From: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
Date: Thu, 17 Jul 2025 16:27:53 +0200
Subject: [PATCH 1/2] Refactor workflows and documentation for improved clarity
and functionality
- Updated CRON.yml and PUSH-MASTER.yml to enhance job naming and descriptions.
- Modified PUSH-OTHER.yml to improve conditional checks for linting and building.
- Adjusted Makefile to allow for version fallback.
- Enhanced README.md with clearer descriptions and new features.
- Updated action.yml to clarify input descriptions.
- Improved entrypoint.sh for better commit handling and logging.
- Added comprehensive WORKFLOWS.md to document GitHub Actions setup.
- Created RELEASE.yml for automated release process and version updates.
---
.github/WORKFLOWS.md | 97 +++++++++++++
.github/workflows/CRON.yml | 8 +-
.github/workflows/PUSH-MASTER.yml | 18 +--
.github/workflows/PUSH-OTHER.yml | 41 ++++--
.github/workflows/RELEASE.yml | 78 ++++++++++
Makefile | 2 +-
README.md | 228 +++++++++++++++++++++++++-----
action.yml | 8 +-
entrypoint.sh | 37 +++--
9 files changed, 442 insertions(+), 75 deletions(-)
create mode 100644 .github/WORKFLOWS.md
create mode 100644 .github/workflows/RELEASE.yml
diff --git a/.github/WORKFLOWS.md b/.github/WORKFLOWS.md
new file mode 100644
index 0000000..a09d3fe
--- /dev/null
+++ b/.github/WORKFLOWS.md
@@ -0,0 +1,97 @@
+# GitHub Actions Workflows Documentation
+
+This repository uses a comprehensive GitHub Actions setup with different workflows for different purposes.
+
+## Workflow Overview
+
+### 1. PUSH-MASTER.yml
+**Trigger**: Push to `master` branch
+
+**Purpose**: Continuous Integration for master branch
+- ✅ Update repository labels
+- ✅ Run Hadolint linting on Dockerfile
+- ✅ Build Docker image (test only, no push)
+
+**Actions**:
+- Labels management
+- Dockerfile linting
+- Docker build test
+
+### 2. PUSH-OTHER.yml
+**Trigger**: Push to any branch except `master`
+
+**Purpose**: Continuous Integration for feature branches
+- ✅ Update repository labels (dry run)
+- ✅ Run Hadolint linting on Dockerfile
+- ✅ Build Docker image (test only for regular branches)
+- ✅ Build & push test Docker images for `test/*` branches
+- ✅ Create Pull Requests based on branch naming conventions
+
+**Special handling for test branches**:
+- Branches starting with `test/` → Build and push Docker images with `test-` prefix
+- Other branches → Build test only (no push)
+
+**Branch naming conventions for auto-PR creation**:
+- `bug/*` → Creates PR with "bugfix" label
+- `dep/*` → Creates PR with "dependency" label
+- `doc/*` → Creates PR with "documentation" label
+- `feat/*` → Creates PR with "feature" label
+- `test/*` → Creates draft PR with "test" label + pushes test Docker images
+- Other branches → Creates PR with "feature" label
+
+### 3. RELEASE.yml
+**Trigger**: GitHub release published
+
+**Purpose**: Production deployment
+- ✅ Build multi-architecture Docker images (amd64, arm64)
+- ✅ Push images to Docker Hub with release version tag
+- ✅ Push images to GitHub Container Registry
+- ✅ Update Docker Hub description
+- ✅ Update `action.yml` with new image version
+
+**Release Process**:
+1. Create GitHub release with version tag (e.g., `v0.11.0`)
+2. Workflow automatically builds and pushes Docker images
+3. Images are tagged with the release version
+4. `action.yml` is updated to reference the new version
+
+### 4. CRON.yml
+**Trigger**: Weekly schedule (Sundays at 5:00 AM UTC)
+
+**Purpose**: Weekly health check and test image refresh
+- ✅ Build Docker image to ensure dependencies still work
+- ✅ Push test images to keep them fresh for testing
+- ✅ Test that the build process is still functional
+
+## Security & Best Practices
+
+### Required Secrets
+- `GITHUB_TOKEN`: Automatically provided by GitHub Actions
+- `DOCKER_TOKEN`: Docker Hub access token for pushing images
+
+### Required Variables
+- `DOCKER_USERNAME`: Docker Hub username
+- `DOCKER_ORG_NAME`: Docker Hub organization name
+
+### Key Features
+- **Multi-architecture support**: Builds for both `amd64` and `arm64`
+- **Dependency updates**: Uses Dependabot for automated dependency updates
+- **Security scanning**: Hadolint for Dockerfile best practices
+- **Release automation**: Automatic Docker image versioning and deployment
+- **Development safety**: Prevents accidental production deployments from development branches
+
+## Deployment Strategy
+
+### Development Flow
+1. Create feature branch with appropriate naming convention
+2. Push changes → Triggers build test and auto-PR creation
+3. Review and merge PR to master → Triggers master build test
+4. Create GitHub release → Triggers production deployment
+
+### Production Deployment
+- Only happens on GitHub releases
+- Ensures only tested, reviewed code reaches production
+- Automatic versioning and tagging
+- Docker Hub and GitHub Container Registry deployment
+
+This setup ensures a safe, automated, and well-tested deployment pipeline while maintaining development velocity.
diff --git a/.github/workflows/CRON.yml b/.github/workflows/CRON.yml
index 837f24d..af3303d 100644
--- a/.github/workflows/CRON.yml
+++ b/.github/workflows/CRON.yml
@@ -1,4 +1,4 @@
-name: Weekly build
+name: Weekly test build & push
on:
schedule:
@@ -6,8 +6,8 @@ on:
- cron: "0 5 */7 * *"
jobs:
- build_and_push:
- name: Build & push
+ build_and_push_test:
+ name: Weekly test build & push
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
@@ -24,7 +24,7 @@ jobs:
image: tonistiigi/binfmt:latest
platforms: amd64,arm64
- - name: Build & push
+ - name: Build & push test image
env:
DOCKER_BUILDKIT: 1
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
diff --git a/.github/workflows/PUSH-MASTER.yml b/.github/workflows/PUSH-MASTER.yml
index 61cd898..a5f425f 100644
--- a/.github/workflows/PUSH-MASTER.yml
+++ b/.github/workflows/PUSH-MASTER.yml
@@ -37,8 +37,8 @@ jobs:
with:
dockerfile: Dockerfile
- build_and_push:
- name: Build & push
+ build_test:
+ name: Build test
needs: lint
runs-on: ubuntu-24.04-arm
steps:
@@ -56,18 +56,8 @@ jobs:
image: tonistiigi/binfmt:latest
platforms: amd64,arm64
- - name: Build & push
+ - name: Build test
env:
DOCKER_BUILDKIT: 1
- DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TERM: xterm-256color
- run: make push
-
- - name: Docker Hub Description
- uses: peter-evans/dockerhub-description@v4.0.2
- with:
- username: ${{ vars.DOCKER_USERNAME }}
- password: ${{ secrets.DOCKER_TOKEN }}
- repository: ${{ vars.DOCKER_ORG_NAME }}/${{ github.event.repository.name }}
- short-description: ${{ github.event.repository.description }}
+ run: make build
diff --git a/.github/workflows/PUSH-OTHER.yml b/.github/workflows/PUSH-OTHER.yml
index e1c1fbd..e92b24d 100644
--- a/.github/workflows/PUSH-OTHER.yml
+++ b/.github/workflows/PUSH-OTHER.yml
@@ -28,7 +28,7 @@ jobs:
lint:
name: Linters
- if: "!startsWith(github.ref, 'refs/heads/dependabot')"
+ if: ${{ !startsWith(github.ref, 'refs/heads/dependabot') }}
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
@@ -39,9 +39,9 @@ jobs:
with:
dockerfile: Dockerfile
- build_and_push:
- name: Build & push
- if: "!startsWith(github.ref, 'refs/heads/dependabot')"
+ build_test:
+ name: Build test
+ if: ${{ !startsWith(github.ref, 'refs/heads/dependabot') && !startsWith(github.ref, 'refs/heads/test/') }}
runs-on: ubuntu-24.04-arm
steps:
- name: Checkout
@@ -58,7 +58,32 @@ jobs:
image: tonistiigi/binfmt:latest
platforms: amd64,arm64
- - name: Build & push
+ - name: Build test
+ env:
+ DOCKER_BUILDKIT: 1
+ TERM: xterm-256color
+ run: make build
+
+ build_and_push_test:
+ name: Build & push test image
+ if: ${{ startsWith(github.ref, 'refs/heads/test/') }}
+ runs-on: ubuntu-24.04-arm
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Docker Buildx
+ uses: docker/setup-buildx-action@v3.11.1
+ with:
+ install: true
+
+ - name: QEMU
+ uses: docker/setup-qemu-action@v3.6.0
+ with:
+ image: tonistiigi/binfmt:latest
+ platforms: amd64,arm64
+
+ - name: Build & push test image
env:
DOCKER_BUILDKIT: 1
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
@@ -92,7 +117,7 @@ jobs:
get_diff: true
- name: PR - dependency (conditional)
- if: "startsWith(github.ref, 'refs/heads/dep') && !startsWith(github.ref, 'refs/heads/dependabot')"
+ if: startsWith(github.ref, 'refs/heads/dep') && !startsWith(github.ref, 'refs/heads/dependabot')
uses: devops-infra/action-pull-request@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -133,8 +158,8 @@ jobs:
draft: true
get_diff: true
- - name: PR - test (conditional)
- if: "!startsWith(github.ref, 'refs/heads/bug') && !startsWith(github.ref, 'refs/heads/dep') && !startsWith(github.ref, 'refs/heads/doc') && !startsWith(github.ref, 'refs/heads/feat') && !startsWith(github.ref, 'refs/heads/test')"
+ - name: PR - other branches (conditional)
+ if: ${{ !(startsWith(github.ref, 'refs/heads/bug') || startsWith(github.ref, 'refs/heads/dep') || startsWith(github.ref, 'refs/heads/doc') || startsWith(github.ref, 'refs/heads/feat') || startsWith(github.ref, 'refs/heads/test')) }}
uses: devops-infra/action-pull-request@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.github/workflows/RELEASE.yml b/.github/workflows/RELEASE.yml
new file mode 100644
index 0000000..6f599d8
--- /dev/null
+++ b/.github/workflows/RELEASE.yml
@@ -0,0 +1,78 @@
+name: Release
+
+on:
+ release:
+ types: [published]
+
+jobs:
+ build_and_push:
+ name: Build & push release
+ runs-on: ubuntu-24.04-arm
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Docker Buildx
+ uses: docker/setup-buildx-action@v3.11.1
+ with:
+ install: true
+
+ - name: QEMU
+ uses: docker/setup-qemu-action@v3.6.0
+ with:
+ image: tonistiigi/binfmt:latest
+ platforms: amd64,arm64
+
+ - name: Extract version from tag
+ id: version
+ run: |
+ VERSION=${GITHUB_REF#refs/tags/}
+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
+ echo "Version: ${VERSION}"
+
+ - name: Build & push release
+ env:
+ DOCKER_BUILDKIT: 1
+ DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ TERM: xterm-256color
+ VERSION: ${{ steps.version.outputs.version }}
+ run: make push
+
+ - name: Docker Hub Description
+ uses: peter-evans/dockerhub-description@v4.0.2
+ with:
+ username: ${{ vars.DOCKER_USERNAME }}
+ password: ${{ secrets.DOCKER_TOKEN }}
+ repository: ${{ vars.DOCKER_ORG_NAME }}/${{ github.event.repository.name }}
+ short-description: ${{ github.event.repository.description }}
+
+ update_action_yml:
+ name: Update action.yml with new version
+ needs: build_and_push
+ runs-on: ubuntu-24.04-arm
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Extract version from tag
+ id: version
+ run: |
+ VERSION=${GITHUB_REF#refs/tags/}
+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
+ echo "Version: ${VERSION}"
+
+ - name: Update action.yml with new version
+ run: |
+ VERSION=${{ steps.version.outputs.version }}
+ sed -i "s|image: docker://devopsinfra/action-commit-push:.*|image: docker://devopsinfra/action-commit-push:${VERSION}|" action.yml
+ git diff action.yml
+
+ - name: Commit updated action.yml
+ uses: ./
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ commit_message: "Update action.yml to use release version ${{ steps.version.outputs.version }}"
+ amend: false
diff --git a/Makefile b/Makefile
index 73eb48c..700ea02 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
phony: help
# Release tag for the action
-VERSION := v0.10.0
+VERSION := $(or $(VERSION),v0.11.0)
# GitHub Actions bogus variables
GITHUB_REF ?= refs/heads/null
diff --git a/README.md b/README.md
index 2c2d6ab..f880dd1 100644
--- a/README.md
+++ b/README.md
@@ -1,26 +1,30 @@
-# GitHub Action for committing changes to a repository.
+# 🚀 GitHub Action for Committing Changes to Repository
-### Supporting `amd64` and `aarch64/arm64` images!
+### 🏗️ Multi-Architecture Support: `amd64` and `aarch64/arm64`
-Useful in combination with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
+### ⚠️ Recent Changes in v0.11.0
+- **Force behavior updated**: `force: true` now uses `git push --force` (breaking change)
+- **New parameter**: `force_with_lease` for safer force pushing with `--force-with-lease`
+- **Amend improvements**: Can now combine `amend: true` with `commit_message` to change commit messages
-Available in Docker Hub: [devopsinfra/action-commit-push:latest](https://hub.docker.com/repository/docker/devopsinfra/action-commit-push)
-
-And GitHub Packages: [ghcr.io/devops-infra/action-commit-push/action-commit-push:latest](https://github.com/orgs/devops-infra/packages/container/package/action-commit-push)
+A powerful GitHub Action for automatically committing and pushing changes back to your repository. Perfect for automation workflows and integrates seamlessly with [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
+
+## 📦 Available on
+- **Docker Hub:** [devopsinfra/action-commit-push:latest](https://hub.docker.com/repository/docker/devopsinfra/action-commit-push)
+- **GitHub Packages:** [ghcr.io/devops-infra/action-commit-push/action-commit-push:latest](https://github.com/orgs/devops-infra/packages/container/package/action-commit-push)
-Features:
-* 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.
-* Can add a timestamp to a branch name (great for cron-based updates):
- * When `target_branch` is set and `add_timestamp` is `true` will create a branch named `${branch_name}/${add_timestamp}`.
- * When `target_branch` is not set and `add_timestamp` is `true` will create a branch named `${add_timestamp}`.
-* Good to combine with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
-* Can use `git push --force` for fast-forward changes with `force` input.
+## ✨ Features
+- **📝 Custom commit messages:** Add custom prefixes and messages to commits
+- **🌿 Branch management:** Create new branches automatically with optional timestamps
+- **⏰ Timestamp support:** Add timestamps to branch names for cron-based updates
+- **🔄 Integration-ready:** Works seamlessly with other DevOps workflows
+- **💪 Force push options:** Support for `--force` and `--force-with-lease` when needed
+- **🔀 Pull request integration:** Perfect companion for automated PR workflows
-## Badge swag
+
+## 📊 Badge Swag
[


@@ -36,7 +40,7 @@ Features:
](https://hub.docker.com/r/devopsinfra/action-commit-push "shields.io")
-## Reference
+## 📖 API Reference
```yaml
- name: Run the Action
@@ -47,33 +51,40 @@ Features:
commit_prefix: "[AUTO]"
commit_message: "Automatic commit"
force: false
- force_without_lease: false
+ force_with_lease: false
target_branch: update/version
```
+### 🔧 Input Parameters
+
| Input Variable | Required | Default | Description |
| ------------------- | -------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| github_token | Yes | `""` | Personal Access Token for GitHub for pushing the code. |
| add_timestamp | No | `false` | Whether to add the timestamp to a new branch name. Uses format `%Y-%m-%dT%H-%M-%SZ`. |
-| amend | No | `false` | Whether to make amendment to the previous commit (`--amend`). Cannot be used together with `commit_message` or `commit_prefix`. |
+| amend | No | `false` | Whether to make an amendment to the previous commit (`--amend`). Can be combined with `commit_message` to change the commit message. |
| commit_prefix | No | `""` | Prefix added to commit message. Combines with `commit_message`. |
-| commit_message | No | `""` | Commit message to set. Combines with `commit_prefix`. Cannot be used together with `amend`. |
-| force | No | `false` | Whether to use force push with lease (`--force-with-lease`). Use only if necessary, e.g. when using `--amend`. And set `fetch-depth: 0` for `actions/checkout`. |
-| force_without_lease | No | `false` | Whether to use force push without lease (`--force`). Use only when you need to overwrite remote changes. Potentially dangerous. |
+| commit_message | No | `""` | Commit message to set. Combines with `commit_prefix`. Can be used with `amend` to change the commit message. |
+| force | No | `false` | Whether to use force push (`--force`). Use only when you need to overwrite remote changes. Potentially dangerous. |
+| force_with_lease | No | `false` | Whether to use force push with lease (`--force-with-lease`). Safer than `force` as it checks for remote changes. Set `fetch-depth: 0` for `actions/checkout`. |
| no_edit | No | `false` | Whether to not edit commit message when using amend (`--no-edit`). |
-| organization_domain | No | `github.com` | Github Enterprise domain name. |
+| organization_domain | No | `github.com` | GitHub Enterprise domain name. |
| target_branch | No | *current branch* | Name of a new branch to push the code into. Creates branch if not existing. |
-| Outputs | Description |
-| ------------- | ------------------------------------------------------------------------ |
-| files_changed | List of changed files. As returned by `git diff --staged --name-status`. |
-| branch_name | Name of the branch code was pushed into. |
+### 📤 Output Parameters
+| Output | Description |
+| ------------- | -------------------------------------------------------------------------- |
+| files_changed | List of changed files, as returned by `git diff --staged --name-status`. |
+| branch_name | Name of the branch code was pushed into. |
-## Examples
-Commit and push changes to currently checked out branch.
+## 💻 Usage Examples
+
+### 📝 Basic Example: Commit and Push to Current Branch
+
+Commit and push changes to the currently checked out branch.
+
```yaml
name: Push changes
on:
@@ -83,7 +94,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
- uses: actions/checkout@master
+ uses: actions/checkout@v4
- name: Change something
run: |
find . -type f -name "*.md" -print0 | xargs -0 sed -i "s/foo/bar/g"
@@ -91,12 +102,15 @@ jobs:
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- commit_message: Replaced foo with bar
+ commit_message: "Replace foo with bar"
```
-Commit and push changes to a new branch and create pull request using my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
+### 🔀 Advanced Example: Commit, Push, and Create Pull Request
+
+Commit and push changes to a new branch and create a pull request using [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
+
```yaml
-name: Push changes
+name: Push changes and create PR
on:
push
jobs:
@@ -104,7 +118,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
- uses: actions/checkout@master
+ uses: actions/checkout@v4
- name: Change something
run: |
find . -type f -name "*.md" -print0 | xargs -0 sed -i "s/foo/bar/g"
@@ -112,11 +126,153 @@ jobs:
uses: devops-infra/action-commit-push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- commit_prefix: "[AUTO-COMMIT] foo/bar replace"
+ commit_prefix: "[AUTO-COMMIT] "
+ commit_message: "Replace foo with bar"
- name: Create pull request
uses: devops-infra/action-pull-request@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- body: "**Automated pull request**
Replaced foo/bar"
+ body: "**Automated pull request**
Replaced foo with bar"
title: ${{ github.event.commits[0].message }}
```
+
+### 💪 Force Push Example: Amending Previous Commit
+
+When you need to amend the previous commit and force push (useful for fixing commit messages or adding forgotten changes).
+
+```yaml
+name: Amend and force push
+on:
+ workflow_dispatch:
+ inputs:
+ new_commit_message:
+ description: 'New commit message'
+ required: true
+ default: 'Updated commit message'
+
+jobs:
+ amend-commit:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository with full history
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0 # Required for force_with_lease
+ - name: Make some changes
+ run: |
+ echo "Additional content" >> README.md
+ - name: Amend and force push with lease
+ uses: devops-infra/action-commit-push@master
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ commit_message: ${{ github.event.inputs.new_commit_message }}
+ amend: true
+ force_with_lease: true # Safer force push option
+```
+
+### 📝 Amend Options
+
+When using `amend: true`, you have several options for handling the commit message:
+
+1. **Change the commit message**: Set `commit_message` to provide a new message
+ ```yaml
+ - uses: devops-infra/action-commit-push@master
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ commit_message: "Fixed typo in documentation"
+ amend: true
+ force_with_lease: true
+ ```
+
+2. **Keep existing message**: Set `no_edit: true` to keep the original commit message
+ ```yaml
+ - uses: devops-infra/action-commit-push@master
+ with:
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ amend: true
+ no_edit: true
+ force_with_lease: true
+ ```
+
+3. **Default behavior**: If neither is set, uses "Files changed:" with file list (when files are modified)
+
+**💡 Note:** Amending works even without file changes - useful for just changing commit messages!
+
+
+## 🚀 Release Process
+
+This action follows a **release-based Docker image deployment strategy**:
+
+- **Development branches**: Only build and test Docker images (no push to Docker Hub)
+- **Test branches (`test/*`)**: Build and push Docker images with `test-` prefix for integration testing
+- **Master branch**: Only build and test Docker images (no push to Docker Hub)
+- **Releases**: Docker images are built and pushed to Docker Hub only when a new GitHub release is created
+- **Weekly builds**: Automated test builds run weekly and push test images
+
+### 🏷️ Creating a New Release
+
+1. Create a new GitHub release with a version tag (e.g., `v0.11.0`)
+2. The release workflow automatically:
+ - Builds multi-architecture Docker images (`amd64`, `arm64`)
+ - Pushes images to Docker Hub with the release version tag
+ - Updates the `action.yml` file to reference the new Docker image version
+ - Updates Docker Hub description
+
+### 🧪 Testing with Test Branches
+
+For testing changes before creating a release:
+
+1. Create a branch starting with `test/` (e.g., `test/new-feature`)
+2. Push your changes to this branch
+3. The workflow automatically builds and pushes Docker images with `test-` prefix
+4. Use the test image in other workflows: `devopsinfra/action-commit-push:test-latest`
+
+**This ensures that:**
+- ✅ Master branch merges don't accidentally publish untested images
+- ✅ Test branches provide safe testing environments
+- ✅ Only stable, released versions are available on Docker Hub
+- ✅ Users can pin to specific, tested versions
+- ✅ Development and testing don't interfere with production images
+
+## ⚠️ Force Push Options
+
+This action provides two force push options for different scenarios:
+
+### 🛡️ `force_with_lease` (Recommended)
+- Uses `git push --force-with-lease`
+- **Safer option** that checks if someone else has pushed changes to the remote branch
+- Prevents accidentally overwriting other people's work
+- **Required:** Set `fetch-depth: 0` in your `actions/checkout` step
+- **Use case:** Amending commits, rebasing, or other history modifications
+
+### ⚡ `force` (Use with Caution)
+- Uses `git push --force`
+- **Potentially dangerous** as it will overwrite remote changes unconditionally
+- No safety checks - will overwrite any remote changes
+- **Use case:** Only when you're absolutely certain you want to overwrite remote changes
+
+**⚠️ Important:** Never use both options simultaneously. `force_with_lease` takes precedence if both are set to `true`.
+
+
+## 🤝 Contributing
+
+Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
+
+
+## 📄 License
+
+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
+
+
+## 🔗 Related Actions
+
+- [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request) - Create pull requests automatically
+- [devops-infra/.github](https://github.com/devops-infra/.github) - Shared GitHub configuration and templates
+
+
+## 💬 Support
+
+If you have any questions or need help, please:
+- 📝 Create an [issue](https://github.com/devops-infra/action-commit-push/issues)
+- 💬 Start a [discussion](https://github.com/devops-infra/action-commit-push/discussions)
+- 🌟 Star this repository if you find it useful!
diff --git a/action.yml b/action.yml
index 90c4ae9..fc2f0d1 100644
--- a/action.yml
+++ b/action.yml
@@ -11,7 +11,7 @@ inputs:
required: false
default: "false"
amend:
- description: Whether to make amendment to the previous commit
+ description: Whether to make amendment to the previous commit (--amend). Can be combined with commit_message to change the message.
required: false
default: "false"
commit_prefix:
@@ -23,11 +23,11 @@ inputs:
required: false
default: ""
force:
- description: Whether to force push
+ description: Whether to use force push (--force). Use only when you need to overwrite remote changes. Potentially dangerous.
required: false
default: "false"
- force_without_lease:
- description: Whether to force push without lease (--force instead of --force-with-lease)
+ force_with_lease:
+ description: Whether to use force push with lease (--force-with-lease). Safer than force as it checks for remote changes.
required: false
default: "false"
no_edit:
diff --git a/entrypoint.sh b/entrypoint.sh
index 70d2cf6..c0acbc3 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -11,7 +11,7 @@ echo " amend: ${INPUT_AMEND}"
echo " commit_prefix: ${INPUT_COMMIT_PREFIX}"
echo " commit_message: ${INPUT_COMMIT_MESSAGE}"
echo " force: ${INPUT_FORCE}"
-echo " force_without_lease: ${INPUT_FORCE_WITHOUT_LEASE}"
+echo " force_with_lease: ${INPUT_FORCE_WITH_LEASE}"
echo " no_edit: ${INPUT_NO_EDIT}"
echo " organization_domain: ${INPUT_ORGANIZATION_DOMAIN}"
echo " target_branch: ${INPUT_TARGET_BRANCH}"
@@ -61,29 +61,50 @@ fi
# Create an auto commit
COMMIT_PARAMS=()
COMMIT_PARAMS+=("--allow-empty")
-if [[ -n ${FILES_CHANGED} ]]; then
- echo "[INFO] Committing changes."
+
+# Commit if there are changes OR if we're amending (even without changes)
+if [[ -n ${FILES_CHANGED} || "${INPUT_AMEND}" == "true" ]]; then
+ if [[ -n ${FILES_CHANGED} ]]; then
+ echo "[INFO] Committing changes."
+ fi
+
if [[ "${INPUT_AMEND}" == "true" ]]; then
COMMIT_PARAMS+=("--amend")
+ echo "[INFO] Amending previous commit."
fi
+
if [[ "${INPUT_NO_EDIT}" == "true" ]]; then
COMMIT_PARAMS+=("--no-edit")
+ echo "[INFO] Using existing commit message (--no-edit)."
git commit "${COMMIT_PARAMS[@]}"
elif [[ -n "${INPUT_COMMIT_MESSAGE}" || -n "${INPUT_COMMIT_PREFIX}" ]]; then
- git commit "${COMMIT_PARAMS[@]}" -am "${INPUT_COMMIT_PREFIX}${INPUT_COMMIT_MESSAGE}" -m "$(echo -e "Files changed:\n${FILES_CHANGED}")"
- else
+ COMMIT_MESSAGE="${INPUT_COMMIT_PREFIX}${INPUT_COMMIT_MESSAGE}"
+ if [[ "${INPUT_AMEND}" == "true" ]]; then
+ echo "[INFO] Setting new commit message: ${COMMIT_MESSAGE}"
+ fi
+
+ if [[ -n ${FILES_CHANGED} ]]; then
+ git commit "${COMMIT_PARAMS[@]}" -am "${COMMIT_MESSAGE}" -m "$(echo -e "Files changed:\n${FILES_CHANGED}")"
+ else
+ git commit "${COMMIT_PARAMS[@]}" -m "${COMMIT_MESSAGE}"
+ fi
+ elif [[ -n ${FILES_CHANGED} ]]; then
git commit "${COMMIT_PARAMS[@]}" -am "Files changed:" -m "${FILES_CHANGED}"
+ else
+ # Amending without files changed and no new message - keep existing message
+ COMMIT_PARAMS+=("--no-edit")
+ git commit "${COMMIT_PARAMS[@]}"
fi
fi
# Push
-if [[ "${INPUT_FORCE_WITHOUT_LEASE}" == "true" ]]; then
+if [[ "${INPUT_FORCE}" == "true" ]]; then
echo "[INFO] Force pushing changes without lease"
git push --force origin "${BRANCH}"
-elif [[ "${INPUT_FORCE}" == "true" ]]; then
+elif [[ "${INPUT_FORCE_WITH_LEASE}" == "true" ]]; then
echo "[INFO] Force pushing changes with lease"
git push --force-with-lease origin "${BRANCH}"
-elif [[ -n ${FILES_CHANGED} ]]; then
+elif [[ -n ${FILES_CHANGED} || "${INPUT_AMEND}" == "true" ]]; then
echo "[INFO] Pushing changes"
git push origin "${BRANCH}"
fi
From e3969b131b574d3316d10898b45b97acb3a935c5 Mon Sep 17 00:00:00 2001
From: Krzysztof Szyper <45788587+ChristophShyper@users.noreply.github.com>
Date: Thu, 17 Jul 2025 16:41:14 +0200
Subject: [PATCH 2/2] Update info message in entrypoint.sh for force
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
entrypoint.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/entrypoint.sh b/entrypoint.sh
index c0acbc3..6172011 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -99,7 +99,7 @@ fi
# Push
if [[ "${INPUT_FORCE}" == "true" ]]; then
- echo "[INFO] Force pushing changes without lease"
+ echo "[INFO] Force pushing changes using --force"
git push --force origin "${BRANCH}"
elif [[ "${INPUT_FORCE_WITH_LEASE}" == "true" ]]; then
echo "[INFO] Force pushing changes with lease"