├── .github └── workflows │ └── nodejs.yml ├── .gitignore ├── Dockerfile ├── README.md ├── entrypoint.sh └── package.json /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Use Node.js 10.x 13 | uses: actions/setup-node@v1 14 | with: 15 | version: 10.x 16 | - name: docker lint 17 | run: | 18 | npm install 19 | npm run build --if-present 20 | npm test 21 | - uses: zbeekman/ShellCheck-Linter-Action@v1.0.1 22 | name: shell linter 23 | - uses: mikeal/publish-to-github-action@master 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .nyc_output 2 | coverage 3 | package-lock.json 4 | node_modules 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.9 2 | 3 | LABEL "com.github.actions.name"="Push new files back to supplied branch name." 4 | LABEL "com.github.actions.description"="A GitHub Action to push any new files back to supplied branch name" 5 | LABEL "com.github.actions.icon"="arrow-up" 6 | LABEL "com.github.actions.color"="blue" 7 | 8 | LABEL "repository"="https://github.com/mikeal/publish-to-github-action" 9 | LABEL "homepage"="https://github.com/mikeal/publish-to-github-action" 10 | LABEL "maintainer"="peaceiris" 11 | 12 | RUN apk --no-cache add openssl git curl openssh-client bash 13 | 14 | COPY entrypoint.sh /entrypoint.sh 15 | ENTRYPOINT [ "/entrypoint.sh" ] 16 | 17 | RUN echo CWD `pwd` \ 18 | && mkdir /tmp/lfs \ 19 | && cd /tmp/lfs \ 20 | && curl -sLO https://github.com/git-lfs/git-lfs/releases/download/v2.6.0/git-lfs-linux-amd64-v2.6.0.tar.gz \ 21 | && tar -zxf git-lfs-linux-amd64-v2.6.0.tar.gz \ 22 | && ./install.sh \ 23 | && cd / \ 24 | && rm -rf /tmp/lfs 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `publish-to-github-action` 2 | 3 | A GitHub Action to push any local file changes, including new files, back to supplied branch name. 4 | 5 | This action is useful to put *after* other actions that modify files in the local checkout 6 | that you'd then like to persist back into the repository. 7 | 8 | Usage: 9 | 10 | ``` 11 | - uses: mikeal/publish-to-github-action@master 12 | env: 13 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 14 | BRANCH_NAME: '' #optional defaults to master 15 | ``` 16 | 17 | If you can get away with only ever writing new files, instead of updating them, you won’t regret it ;) Every time you update a file you retain the history of the file. Over time this can become quite large and contain a lot of duplicate data, even when using Git LFS as described below. The only way to garbage collect this historical data is to use a [hefty Java program called BFG](https://rtyley.github.io/bfg-repo-cleaner/) to re-write the history. 18 | 19 | ## Large Files (Git LFS) 20 | 21 | For large data files, or if you have a lot of data, this action comes with the dependencies required for [Git LFS](https://git-lfs.github.com/), so as long as you've initialized and configured LFS for the files you're adding they will be added and pushed via Git LFS. This is particularly helpful if you are running into GitHub's 1GB data limit. 22 | 23 | One thing to note is that files in Git LFS are stored out of the repository and then pulled in by LFS specific tools. This means that the default `git checkout` in an action won't have the real file data, it will have file stubs that tell LFS how to download the files. If your action needs these files to be fully available you have two options. 24 | 25 | 1. Set the `lfs` option to true in your [checkout action](https://github.com/actions/checkout#usage). This will download **all** the LFS files, which is rarely ideal and is a great way to blow out your LFS transfer limit ;) 26 | 2. Prior to reading the files, run `git lfs install` and `git pull --include files-i-want/*` in your action. This will pull out only the selected files. 27 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # check values 4 | if [ -z "${GITHUB_TOKEN}" ]; then 5 | echo "error: not found GITHUB_TOKEN" 6 | exit 1 7 | fi 8 | 9 | if [ -z "${BRANCH_NAME}" ]; then 10 | export BRANCH_NAME=master 11 | fi 12 | 13 | # initialize git 14 | remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" 15 | git config http.sslVerify false 16 | git config user.name "Automated Publisher" 17 | git config user.email "actions@users.noreply.github.com" 18 | git remote add publisher "${remote_repo}" 19 | git show-ref # useful for debugging 20 | git branch --verbose 21 | 22 | # install lfs hooks 23 | git lfs install 24 | 25 | # publish any new files 26 | git checkout ${BRANCH_NAME} 27 | git add -A 28 | timestamp=$(date -u) 29 | git commit -m "Automated publish: ${timestamp} ${GITHUB_SHA}" || exit 0 30 | git pull --rebase publisher ${BRANCH_NAME} 31 | git push publisher ${BRANCH_NAME} 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "publish-to-github-action", 3 | "version": "0.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "dockerlint Dockerfile" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mikeal/publish-to-github-action.git" 12 | }, 13 | "keywords": [], 14 | "author": "Mikeal Rogers (https://www.mikealrogers.com/)", 15 | "license": "(Apache-2.0 AND MIT)", 16 | "bugs": { 17 | "url": "https://github.com/mikeal/publish-to-github-action/issues" 18 | }, 19 | "homepage": "https://github.com/mikeal/publish-to-github-action#readme", 20 | "dependencies": { 21 | "dockerlint": "^0.3.9" 22 | } 23 | } 24 | --------------------------------------------------------------------------------