Skip to content

Commit

Permalink
chore: from Dockerfile to js
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu4k committed Jul 20, 2020
1 parent 8b6aa8b commit 1233dff
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 44 deletions.
6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 actions-js team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 56 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
# push
# GitHub Action for GitHub Commit & Push

Push changes made by actions right back into the current repository.
The GitHub Actions for commiting & pushing to GitHub repository local changes authorizing using GitHub token.

```yml
uses: actions-js/push@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
With ease:
- update new code placed in the repository, e.g. by running a linter on it,
- track changes in script results using Git as archive,
- publish page using GitHub-Pages,
- mirror changes to a separate repository.

## Usage

### Example Workflow file

An example workflow to authenticate with GitHub Platform:

```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- name: Create local changes
run: |
...
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
```
### Inputs
| name | value | default | description |
| ------------ | ------ | ----------------- | ----------- |
| github_token | string | | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. |
| user_email | string | [email protected] | Email used to configure user.email in `git config`. |
| user_name | string | GitHub Action | Name used to configure user.name in `git config`. |
| branch | string | 'master' | Destination branch to push changes. |
| force | boolean | false | Determines if force push is used. |
| tags | boolean | false | Determines if `--tags` is used. |
| directory | string | '.' | Directory to change to before pushing. |
| repository | string | '' | Repository name. Default or empty repository name represents current github repository. If you want to push to other repository, you should make a [personal access token](https://github.com/settings/tokens) and use it as the `github_token` input. |

## License

The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).

## Credits

This is a slight modification of the [ad-m/github-push-action](https://github.com/ad-m/github-push-action) action.

## No affiliation with GitHub Inc.

GitHub are registered trademarks of GitHub, Inc. GitHub name used in this project are for identification purposes only. The project is not associated in any way with GitHub Inc. and is not an official solution of GitHub Inc. It was made available in order to facilitate the use of the site GitHub.
37 changes: 34 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
name: 'Push'
name: 'GitHub Commit & Push'
description: 'Push changes made by actions right back into the current repository.'
author: "actions-js"
inputs:
github_token:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
required: true
user_email:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
default: '[email protected]'
required: false
user_name:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
default: 'Github Action'
required: false
repository:
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
default: ''
required: false
branch:
description: 'Destination branch to push changes'
required: false
default: 'master'
force:
description: 'Determines if force push is used'
required: false
tags:
description: 'Determines if --tags is used'
required: false
directory:
description: 'Directory to change to before pushing.'
required: false
default: '.'
runs:
using: 'docker'
image: 'Dockerfile'
using: 'node12'
main: 'start.js'
branding:
icon: 'arrow-up-circle'
color: 'green'
28 changes: 0 additions & 28 deletions entrypoint.sh

This file was deleted.

26 changes: 26 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const spawn = require('child_process').spawn;
const path = require("path");

const exec = (cmd, args=[]) => new Promise((resolve, reject) => {
console.log(`Started: ${cmd} ${args.join(" ")}`)
const app = spawn(cmd, args, { stdio: 'inherit' });
app.on('close', code => {
if(code !== 0){
err = new Error(`Invalid status code: ${code}`);
err.code = code;
return reject(err);
};
return resolve(code);
});
app.on('error', reject);
});

const main = async () => {
await exec('bash', [path.join(__dirname, './start.sh')]);
};

main().catch(err => {
console.error(err);
console.error(err.stack);
process.exit(err.code || -1);
})
40 changes: 40 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
set -e

INPUT_USER_EMAIL=${INPUT_USER_EMAIL:-'[email protected]'}
INPUT_USER_NAME=${INPUT_USER_NAME:-'GitHub Action'}
INPUT_BRANCH=${INPUT_BRANCH:-master}
INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
_FORCE_OPTION=''
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}

echo "Push to branch $INPUT_BRANCH";
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".';
exit 1;
};

if ${INPUT_FORCE}; then
_FORCE_OPTION='--force'
fi

if ${INPUT_TAGS}; then
_TAGS='--tags'
fi

cd ${INPUT_DIRECTORY}

remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"

git config http.sslVerify false
git config --local user.email "${INPUT_USER_EMAIL}"
git config --local user.name "${INPUT_USER_NAME}"

timestamp=$(date -u)

git add -A
git commit -m "chore: autopublish ${timestamp}" || exit 0

git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;

0 comments on commit 1233dff

Please sign in to comment.