diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 20c55da..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: Test and Tag - -on: - push: - branches: - # explicit deny all here to make sure there isnt a commit loop - - '!*' - - main - -jobs: - test_and_tag: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: check if tag already exists - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0 - - - name: create test file - run: echo $(date) > tmp.txt - - - name: create test directory - run: mkdir -p tmp && cp tmp.txt tmp && echo "second cool file" > tmp/tmp2.txt - - - name: test with file - uses: ./ - id: filetest - with: - source: tmp.txt - destination_repo: leigholiver/commit-with-deploy-key - destination_branch: file_test - deploy_key: ${{ secrets.DEPLOY_KEY }} - - - name: test commit hash output - run: echo "the commit hash for the file test is ${{ steps.filetest.outputs.commit_hash }}" - - - name: test with directory - uses: ./ - with: - source: tmp - destination_repo: leigholiver/commit-with-deploy-key - destination_branch: directory_test - deploy_key: ${{ secrets.DEPLOY_KEY }} - - - name: test destination directory - uses: ./ - with: - source: tmp - destination_repo: leigholiver/commit-with-deploy-key - destination_branch: destination_directory_test - destination_folder: destination - deploy_key: ${{ secrets.DEPLOY_KEY }} - - - name: test destination directory with removal - uses: ./ - with: - source: tmp - destination_repo: leigholiver/commit-with-deploy-key - destination_branch: destination_directory_test_with_delete - delete_destination: true - deploy_key: ${{ secrets.DEPLOY_KEY }} - - - name: test with different username - uses: ./ - with: - source: tmp.txt - destination_repo: leigholiver/commit-with-deploy-key - destination_branch: username_test - deploy_key: ${{ secrets.DEPLOY_KEY }} - git_username: some different user - - - name: test with different commit message - uses: ./ - with: - source: tmp.txt - destination_repo: leigholiver/commit-with-deploy-key - destination_branch: commit_message_test - deploy_key: ${{ secrets.DEPLOY_KEY }} - commit_message: testing a custom commit message (${{ github.sha }}) - - - name: create tag - run: git config --global user.email "${{ github.actor }}" && git config --global user.name "${{ github.actor }}" && git tag -a -m "$(cat VERSION)" $(cat VERSION) && git push --follow-tags diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index bee5730..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -# Container image that runs your code -FROM alpine:3.10 - -RUN apk update && apk add git openssh-client - -# Copies your code file from your action repository to the filesystem path `/` of the container -COPY entrypoint.sh /entrypoint.sh - -# Code file to execute when the docker container starts up (`entrypoint.sh`) -ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md deleted file mode 100644 index 72f7778..0000000 --- a/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Commit with deploy key -Action to commit a file/directory to another repo using a deploy key. - -## Example usage -* Create an SSH key pair to use for the commits -* Add the public key to your destination repo as a deploy key with push access -* Add the private key to your source repo as a secret - -```yaml -uses: leigholiver/commit-with-deploy-key@v1.0.0 -with: - source: build_output - destination_folder: dist - destination_repo: leigholiver/commit-with-deploy-key - deploy_key: ${{ secrets.DEPLOY_KEY }} -``` - -## Inputs -### `source` -**Required** The file/directory to commit - -### `deploy_key` -**Required** Private SSH key to use for the commit. The public key must be added to the destination repostitory as a deploy key, with push access - -### `destination_repo` -**Required** Git repository to push changes to - -### `destination_folder` -Directory in the destination repo to push changes to (default `.`) - -### `destination_branch` -Branch in destination repo to push changes to (default `main`) - -### `delete_destination` -Delete destination directory contents before copy? (default `false`) - -### `git_username`/`git_email` -Github user to use for the commit (default: `${{ github.actor }}`) - -### `commit_message` -Commit message (default ` from `) - -## Outputs -### `commit_hash` -SHA hash of the generated commit diff --git a/VERSION b/VERSION deleted file mode 100644 index 0ec25f7..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -v1.0.0 diff --git a/action.yml b/action.yml deleted file mode 100644 index 971c6bb..0000000 --- a/action.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: 'Commit with deploy key' -description: 'Commit to another repository using a deploy key' -inputs: - source: - description: 'The file/directory to commit' - required: true - deploy_key: - description: 'Private SSH key. Public key must be added to the destination repostitory as a deploy key with push access' - required: true - destination_repo: - description: 'Git repository to push changes to' - required: true - destination_folder: - description: 'Directory in destination repo to push changes to' - required: false - default: '.' - destination_branch: - description: 'Branch in destination repo to push changes to (default `main`)' - required: false - default: 'main' - delete_destination: - description: 'Delete destination directory contents before copy? (default `false`)' - required: false - default: false - git_username: - description: 'Git username' - required: false - default: ${{ github.actor }} - git_email: - description: 'Git email address' - required: false - default: ${{ github.actor }} - commit_message: - description: 'Commit message' - required: false - default: "${{ github.job }} from https://github.com/${{ github.repository }}/commit/${{ github.sha }}" -outputs: - commit_hash: - description: 'The SHA hash of the generated commit' -runs: - using: 'docker' - image: 'Dockerfile' - args: - - ${{ inputs.source }} - - ${{ inputs.destination_repo }} - - ${{ inputs.destination_folder }} - - ${{ inputs.delete_destination }} - - ${{ inputs.deploy_key }} - - ${{ inputs.git_username }} - - ${{ inputs.git_email }} - - ${{ inputs.commit_message }} diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 913bc34..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -l -set -e - -if [ ! -f "${INPUT_SOURCE}" ] && [ ! -d "${INPUT_SOURCE}" ]; then - echo "No source specified" - exit 1 -fi - -# set up some directories -CALLING_DIR=$(pwd) -WORKING_DIR=$(mktemp -d) -REAL_DESTINATION=$(realpath $WORKING_DIR/$INPUT_DESTINATION_FOLDER)/ - -# set up the github deploy key -mkdir -p ~/.ssh -echo "${INPUT_DEPLOY_KEY}" > ~/.ssh/id_rsa -chmod 600 ~/.ssh/id_rsa - -# set up git -git config --global user.name "${INPUT_GIT_USERNAME}" -git config --global user.email "${INPUT_GIT_EMAIL}" -ssh-keyscan -H github.com > ~/.ssh/known_hosts -GIT_SSH='ssh -i /github/home/.ssh/id_rsa -o UserKnownHostsFile=/github/home/.ssh/known_hosts' - -# clone the repo into our working directory and cd to it -GIT_SSH_COMMAND=$GIT_SSH git clone git@github.com:$INPUT_DESTINATION_REPO.git $WORKING_DIR -cd $WORKING_DIR - -# checkout the destination branch, creating it if it doesn't exist -git checkout $INPUT_DESTINATION_BRANCH || git checkout -b $INPUT_DESTINATION_BRANCH - -# ensure destination directory exists, and is emptied if appropriate -mkdir -p $REAL_DESTINATION -cd $REAL_DESTINATION -if [ "${INPUT_DELETE_DESTINATION}" = "true" ]; then - git rm -rf . -fi - -# do the copy -if [ -f $CALLING_DIR/$INPUT_SOURCE ]; then - cp -a $CALLING_DIR/$INPUT_SOURCE . -elif [ -d $CALLING_DIR/$INPUT_SOURCE ]; then - cp -a $CALLING_DIR/$INPUT_SOURCE/* . -fi - -# commit and push -git add . -git commit -m "${INPUT_COMMIT_MESSAGE}" -GIT_SSH_COMMAND=$GIT_SSH git push -u origin $INPUT_DESTINATION_BRANCH - -# output the commit hash -echo "::set-output name=commit_hash::$(git rev-parse HEAD)" -exit 0 diff --git a/tmp.txt b/tmp.txt new file mode 100644 index 0000000..c7aa326 --- /dev/null +++ b/tmp.txt @@ -0,0 +1 @@ +Tue Mar 12 14:20:22 UTC 2024 diff --git a/tmp2.txt b/tmp2.txt new file mode 100644 index 0000000..e2eac02 --- /dev/null +++ b/tmp2.txt @@ -0,0 +1 @@ +second cool file