├── Dockerfile ├── README.md ├── action.yml └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | # Container image that runs your code 2 | FROM alpine:3.10 3 | 4 | # Copies your code file from your action repository to the filesystem path `/` of the container 5 | COPY entrypoint.sh /entrypoint.sh 6 | 7 | RUN apk --update --no-cache add git && apk add bash && apk add --update nodejs npm 8 | 9 | # Code file to execute when the docker container starts up (`entrypoint.sh`) 10 | ENTRYPOINT ["/entrypoint.sh"] 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Commit and push to remote branch 2 | 3 | This action will commit and push to a specific remote branch. 4 | 5 | ## Inputs 6 | 7 | ### `branch` 8 | 9 | **Required** The branch name of the branch to commit and push to. 10 | 11 | If the branch does not already exist, it will be created for you. 12 | 13 | ### `commit_message` 14 | 15 | Custom commit message. **default** "Automated commit from action"" 16 | 17 | ## Example usage 18 | ``` 19 | - name: Push to built branch 20 | uses: Automattic/action-commit-to-branch@master 21 | with: 22 | branch: 'master-built' 23 | commit_message: 'Build master' 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required 26 | ``` 27 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Commit and push to branch' 2 | description: 'Commits and pushes the result of the action to a remote branch.' 3 | author: '@automattic/jetpack' 4 | inputs: 5 | branch: 6 | description: 'Branch ref to push the changes to' 7 | required: true 8 | commit_message: 9 | description: 'Write the commit message' 10 | required: false 11 | default: 'Automated commit from action' 12 | runs: 13 | using: 'docker' 14 | image: 'Dockerfile' -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | git_setup() { 4 | cat <<- EOF > $HOME/.netrc 5 | machine github.com 6 | login $GITHUB_ACTOR 7 | password $GITHUB_TOKEN 8 | machine api.github.com 9 | login $GITHUB_ACTOR 10 | password $GITHUB_TOKEN 11 | EOF 12 | chmod 600 $HOME/.netrc 13 | 14 | git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" 15 | git config --global user.name "$GITHUB_ACTOR" 16 | } 17 | 18 | git_setup 19 | git remote update 20 | git fetch --all 21 | 22 | git stash 23 | 24 | # Will create branch if it does not exist 25 | if [[ $( git branch -r | grep "$INPUT_BRANCH" ) ]]; then 26 | git checkout "${INPUT_BRANCH}" 27 | else 28 | git checkout -b "${INPUT_BRANCH}" 29 | fi 30 | 31 | git stash pop 32 | git add . 33 | git commit -m "${INPUT_COMMIT_MESSAGE}" 34 | git push --set-upstream origin "${INPUT_BRANCH}" 35 | --------------------------------------------------------------------------------