Skip to content

Commit 1233dff

Browse files
author
Qu4k
committed
chore: from Dockerfile to js
1 parent 8b6aa8b commit 1233dff

File tree

7 files changed

+177
-44
lines changed

7 files changed

+177
-44
lines changed

Dockerfile

-6
This file was deleted.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 actions-js team
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.

README.md

+56-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,58 @@
1-
# push
1+
# GitHub Action for GitHub Commit & Push
22

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

5-
```yml
6-
uses: actions-js/push@v1
7-
env:
8-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9-
```
5+
With ease:
6+
- update new code placed in the repository, e.g. by running a linter on it,
7+
- track changes in script results using Git as archive,
8+
- publish page using GitHub-Pages,
9+
- mirror changes to a separate repository.
10+
11+
## Usage
12+
13+
### Example Workflow file
14+
15+
An example workflow to authenticate with GitHub Platform:
16+
17+
```yaml
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@master
23+
with:
24+
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
25+
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
26+
- name: Create local changes
27+
run: |
28+
...
29+
- name: Commit & Push changes
30+
uses: actions-js/push@master
31+
with:
32+
github_token: ${{ secrets.GITHUB_TOKEN }}
33+
```
34+
35+
### Inputs
36+
37+
| name | value | default | description |
38+
| ------------ | ------ | ----------------- | ----------- |
39+
| github_token | string | | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. |
40+
| user_email | string | action@github.com | Email used to configure user.email in `git config`. |
41+
| user_name | string | GitHub Action | Name used to configure user.name in `git config`. |
42+
| branch | string | 'master' | Destination branch to push changes. |
43+
| force | boolean | false | Determines if force push is used. |
44+
| tags | boolean | false | Determines if `--tags` is used. |
45+
| directory | string | '.' | Directory to change to before pushing. |
46+
| 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. |
47+
48+
## License
49+
50+
The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).
51+
52+
## Credits
53+
54+
This is a slight modification of the [ad-m/github-push-action](https://github.com/ad-m/github-push-action) action.
55+
56+
## No affiliation with GitHub Inc.
57+
58+
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.

action.yml

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
1-
name: 'Push'
1+
name: 'GitHub Commit & Push'
22
description: 'Push changes made by actions right back into the current repository.'
3+
author: "actions-js"
4+
inputs:
5+
github_token:
6+
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
7+
required: true
8+
user_email:
9+
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
10+
default: 'action@github.com'
11+
required: false
12+
user_name:
13+
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
14+
default: 'Github Action'
15+
required: false
16+
repository:
17+
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
18+
default: ''
19+
required: false
20+
branch:
21+
description: 'Destination branch to push changes'
22+
required: false
23+
default: 'master'
24+
force:
25+
description: 'Determines if force push is used'
26+
required: false
27+
tags:
28+
description: 'Determines if --tags is used'
29+
required: false
30+
directory:
31+
description: 'Directory to change to before pushing.'
32+
required: false
33+
default: '.'
334
runs:
4-
using: 'docker'
5-
image: 'Dockerfile'
35+
using: 'node12'
36+
main: 'start.js'
637
branding:
738
icon: 'arrow-up-circle'
839
color: 'green'

entrypoint.sh

-28
This file was deleted.

start.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const spawn = require('child_process').spawn;
2+
const path = require("path");
3+
4+
const exec = (cmd, args=[]) => new Promise((resolve, reject) => {
5+
console.log(`Started: ${cmd} ${args.join(" ")}`)
6+
const app = spawn(cmd, args, { stdio: 'inherit' });
7+
app.on('close', code => {
8+
if(code !== 0){
9+
err = new Error(`Invalid status code: ${code}`);
10+
err.code = code;
11+
return reject(err);
12+
};
13+
return resolve(code);
14+
});
15+
app.on('error', reject);
16+
});
17+
18+
const main = async () => {
19+
await exec('bash', [path.join(__dirname, './start.sh')]);
20+
};
21+
22+
main().catch(err => {
23+
console.error(err);
24+
console.error(err.stack);
25+
process.exit(err.code || -1);
26+
})

start.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
set -e
3+
4+
INPUT_USER_EMAIL=${INPUT_USER_EMAIL:-'action@github.com'}
5+
INPUT_USER_NAME=${INPUT_USER_NAME:-'GitHub Action'}
6+
INPUT_BRANCH=${INPUT_BRANCH:-master}
7+
INPUT_FORCE=${INPUT_FORCE:-false}
8+
INPUT_TAGS=${INPUT_TAGS:-false}
9+
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
10+
_FORCE_OPTION=''
11+
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
12+
13+
echo "Push to branch $INPUT_BRANCH";
14+
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
15+
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".';
16+
exit 1;
17+
};
18+
19+
if ${INPUT_FORCE}; then
20+
_FORCE_OPTION='--force'
21+
fi
22+
23+
if ${INPUT_TAGS}; then
24+
_TAGS='--tags'
25+
fi
26+
27+
cd ${INPUT_DIRECTORY}
28+
29+
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
30+
31+
git config http.sslVerify false
32+
git config --local user.email "${INPUT_USER_EMAIL}"
33+
git config --local user.name "${INPUT_USER_NAME}"
34+
35+
timestamp=$(date -u)
36+
37+
git add -A
38+
git commit -m "chore: autopublish ${timestamp}" || exit 0
39+
40+
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;

0 commit comments

Comments
 (0)