Repository navigation
Automatic git-commit #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e37c9fc
test git-commit github action
a7a3150
create pull request automatically
d93c972
update env variables and pr generation
4a56051
try to change PR base
2522ebd
git commit multiple files at once
7eba2c4
git commit specific folder
82adced
commit whole folder
6929d97
test all workflows
ef0eeae
checkout before copying files
73f8285
remove need of passing user email
98ee1ef
use github bot instead of real user
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: Git commit | ||
|
|
||
| on: [pull_request] | ||
|
|
||
| env: | ||
| sha: $GITHUB_SHA | ||
|
|
||
| jobs: | ||
| git-commit: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Mark test file | ||
| run: | | ||
| echo $GITHUB_SHA > test02.md | ||
| mkdir docs | ||
| echo $GITHUB_SHA > docs/test01.md | ||
| echo $GITHUB_SHA > docs/test02.md | ||
| mkdir docs-test-folder | ||
| echo $GITHUB_SHA > docs-test-folder/test01.md | ||
| echo $(pwd) | ||
|
|
||
| - name: Push specific file | ||
| uses: ./git-commit | ||
| env: | ||
| API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| src: 'test02.md' | ||
| dst_branch: 'git-commit-file' | ||
| pr_create: 'true' | ||
| pr_base: 'master' | ||
| pr_title: "Push specific file: ${{ github.repository }}" | ||
|
|
||
| - name: Push specific folder | ||
| uses: ./git-commit | ||
| env: | ||
| API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| src: 'docs-test-folder/' | ||
| dst: 'docs-test-folder/' | ||
| dst_branch: 'git-commit-folder' | ||
| pr_create: 'true' | ||
| pr_base: 'master' | ||
|
|
||
| - name: Push multiple files | ||
| uses: ./git-commit | ||
| env: | ||
| API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| src: 'docs/*.md' | ||
| dst: 'docs/' | ||
| dst_branch: 'git-commit-multiple-files' | ||
| pr_create: 'true' | ||
| pr_base: 'master' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| FROM alpine | ||
|
|
||
| RUN apk update && \ | ||
| apk upgrade && \ | ||
| apk add git curl | ||
|
|
||
| ADD ./entrypoint.sh /entrypoint.sh | ||
|
|
||
| ENTRYPOINT [ "/entrypoint.sh" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| name: 'Git commit' | ||
| description: 'Commit changed file to destination repository' | ||
| inputs: | ||
| src: | ||
| description: 'Source file from the origin directory. Can be a file, glob (`*.json`) or folder' | ||
| required: true | ||
| dst: | ||
| description: 'Directory to push the source to. Defaults to same folder as the source input' | ||
| required: false | ||
| dst_branch: | ||
| description: 'Destination branch' | ||
| required: true | ||
| # See https://api.github.com/users/github-actions%5Bbot%5D | ||
| user_name: | ||
| description: 'GitHub username for the commit. Defaults to GITHUB_ACTOR' | ||
| required: false | ||
| default: 'github-actions[bot]' | ||
| user_email: | ||
| description: 'Email for the git commit. Defaults to commit author email' | ||
| required: false | ||
| default: '41898282+github-actions[bot]@users.noreply.github.com' | ||
| repository: | ||
| description: 'Destination repository, if not provided it will commit back to the same repo' | ||
| required: false | ||
| commit_message: | ||
| description: 'A custom message for the commit' | ||
| required: false | ||
| pr_create: | ||
| description: 'Create pull request automatically if changes are successfully commited' | ||
| required: false | ||
| default: "false" | ||
| pr_title: | ||
| description: 'Pull request title' | ||
| required: false | ||
| pr_description: | ||
| description: 'Pull request description' | ||
| required: false | ||
| pr_base: | ||
| description: 'Create pull request again specific base. Defaults to master branch' | ||
| required: false | ||
| default: 'master' | ||
| runs: | ||
| using: 'docker' | ||
| image: 'Dockerfile' | ||
| args: | ||
| - ${{ inputs.src }} | ||
| - ${{ inputs.dst }} | ||
| - ${{ inputs.user-email }} | ||
| - ${{ inputs.user-name }} | ||
| - ${{ inputs.repository }} | ||
| - ${{ inputs.branch }} | ||
| - ${{ inputs.commit-message }} | ||
| branding: | ||
| icon: 'git-commit' | ||
| color: 'green' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -e | ||
| set -x | ||
|
|
||
| if [ -z "$INPUT_REPOSITORY" ] | ||
| then | ||
| INPUT_REPOSITORY="${GITHUB_REPOSITORY}" | ||
| fi | ||
|
|
||
| if [ -z "$INPUT_COMMIT_MESSAGE" ] | ||
| then | ||
| INPUT_COMMIT_MESSAGE="Generated from https://github.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}" | ||
| fi | ||
|
|
||
| if [ -z "$INPUT_PR_TITLE" ] | ||
| then | ||
| INPUT_PR_TITLE="Automatic update from: ${GITHUB_REPOSITORY}" | ||
| fi | ||
|
|
||
| if [ -z "$INPUT_PR_DESCRIPTION" ] | ||
| then | ||
| INPUT_PR_DESCRIPTION=${INPUT_COMMIT_MESSAGE} | ||
| fi | ||
|
|
||
| if [ -z "$INPUT_DST_BRANCH" ] | ||
| then | ||
| INPUT_DST_BRANCH=${GITHUB_HEAD_REF} | ||
| fi | ||
|
|
||
| CLONE_DIR=$(mktemp -d) | ||
|
|
||
| echo "Cloning destination git repository" | ||
| git config --global user.name "$INPUT_USER_NAME" | ||
| git config --global user.email "$INPUT_USER_EMAIL" | ||
| git clone "https://x-access-token:$API_TOKEN_GITHUB@github.com/$INPUT_REPOSITORY.git" "$CLONE_DIR" | ||
|
|
||
| BASE_DIR=$(pwd) | ||
| cd "$CLONE_DIR" | ||
|
|
||
| echo "Creating new branch: ${INPUT_DST_BRANCH}" | ||
| git checkout -b "$INPUT_DST_BRANCH" | ||
| git reset --hard "origin/$INPUT_DST_BRANCH" || true | ||
|
|
||
| DEST_COPY="$CLONE_DIR/$INPUT_DST" | ||
| if [ "$INPUT_DST" != "" ] | ||
| then | ||
| mkdir -p $DEST_COPY | ||
| fi | ||
|
|
||
| echo "Copying contents to git repo" | ||
| cp -R $BASE_DIR/$INPUT_SRC "$DEST_COPY" | ||
|
|
||
| echo "Adding git commit" | ||
| git add . | ||
| if git status | grep -q "Changes to be committed" | ||
| then | ||
| git commit --message "$INPUT_COMMIT_MESSAGE" | ||
| echo "Pushing git commit" | ||
| git push -u origin HEAD:"$INPUT_DST_BRANCH" | ||
|
|
||
| if [ "$INPUT_PR_CREATE" == "true" ] | ||
| then | ||
| PR_DESCRIPTION_ESCAPED="${INPUT_PR_DESCRIPTION//$'\n'/\\n}" | ||
|
|
||
| curl --connect-timeout 10 \ | ||
| -u "${INPUT_USER_NAME}:${API_TOKEN_GITHUB}" \ | ||
| -X POST -H 'Content-Type: application/json' \ | ||
| --data "{\"head\":\"$INPUT_DST_BRANCH\",\"base\":\"${INPUT_PR_BASE}\", \"title\": \"${INPUT_PR_TITLE}\", \"body\": \"${PR_DESCRIPTION_ESCAPED}\"}" \ | ||
| "https://api.github.com/repos/{$INPUT_REPOSITORY}/pulls" | ||
| fi | ||
| else | ||
| echo "No changes detected" | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call this GITHUB_TOKEN too?