├── Dockerfile ├── git-bash-wrapper ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | LABEL "com.github.actions.name"="git-bash" 4 | LABEL "com.github.actions.description"="Run a command or script in a Git-ready environment" 5 | LABEL "com.github.actions.icon"="hash" 6 | LABEL "com.github.actions.color"="black" 7 | 8 | RUN set -e -x; \ 9 | apk add --no-cache \ 10 | bash \ 11 | curl \ 12 | jq \ 13 | git \ 14 | coreutils \ 15 | openssh-client \ 16 | ; 17 | 18 | COPY git-bash-wrapper /usr/local/bin/ 19 | 20 | ENTRYPOINT ["/usr/local/bin/git-bash-wrapper"] 21 | -------------------------------------------------------------------------------- /git-bash-wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e -u -o pipefail 3 | 4 | # Configure known hosts 5 | echo "github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl" >>/etc/ssh/ssh_known_hosts 6 | 7 | # Configure ssh authentication 8 | if [ -n "${SSH_KEY:-}" ] || [ -n "${SSH_KEY_VAR:-}" ]; then 9 | eval "$(ssh-agent -s)" >/dev/null 10 | mkfifo -m 600 ~/.ssh_key.fifo && printf -- "${!SSH_KEY_VAR:-"$SSH_KEY"}\n" >~/.ssh_key.fifo | ssh-add ~/.ssh_key.fifo && rm ~/.ssh_key.fifo 11 | fi 12 | 13 | # Configure Git user 14 | if [ -n "${GITHUB_TOKEN:-}" ]; then 15 | gh_actor_profile="$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/users/${GITHUB_ACTOR}")" 16 | git config --global user.name "$(printf '%s' "$gh_actor_profile" | jq -r .name)" 17 | git config --global user.email "$(printf '%s' "$gh_actor_profile" | jq -r .email)" 18 | fi 19 | 20 | # Run command 21 | "$@" 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Florian Kaiser 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [github-action-git-bash](https://github.com/fnkr/github-action-git-bash) 2 | 3 | GitHub Action to run a command or script in a Git-ready environment. 4 | Possible use cases include push mirroring, committing and pushing changes, 5 | merging branches, or creating tags from a CI pipeline. 6 | 7 | ## Secrets 8 | 9 | - `GITHUB_TOKEN` — **Optional.** If set, the action will set Git's `user.name` and `user.email` options to the actors name and email. This is useful when creating commits. 10 | - `SSH_KEY` — **Optional.** If set, the action will start an SSH agent and insert the key. This is useful for authenticating with remote repositories (e.g. for push mirroring). The secret must contain an unencrypted private key without trailing line feed. 11 | 12 | ## Variables 13 | 14 | - `SSH_KEY_VAR` — **Optional.** Name of the `SSH_KEY` secret. This can be useful if the action is used multiple times in a workflow. 15 | 16 | ## Usage example 17 | 18 | ```hcl 19 | workflow "On push" { 20 | on = "push" 21 | resolves = ["Update mirror"] 22 | } 23 | 24 | action "Update mirror" { 25 | uses = "fnkr/github-action-git-bash@v1" 26 | secrets = ["GITHUB_TOKEN", "SSH_KEY"] 27 | args = ["bash", "-c", "{ [ \"$(git rev-parse --abbrev-ref HEAD)\" = \"master\" ] || exit 78; } && rm -rf .github && git add -A .github && git commit -m \"Remove .github\" && git remote set-url origin git@github.com:GITHUB/PROJECT.git && git push --force origin master"] 28 | } 29 | ``` 30 | --------------------------------------------------------------------------------