You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by pa...@apache.org on 2021/01/06 03:19:07 UTC

[beam] branch master updated: Copying Github action into our own repository to comply with Apache security requirements

This is an automated email from the ASF dual-hosted git repository.

pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 9276a8c  Copying Github action into our own repository to comply with Apache security requirements
     new b2ad4dd  Merge pull request #13670 from [BEAM-11569] Clone ad-m/github-push-action into Beam repository to comply with Apache security requirements
9276a8c is described below

commit 9276a8cbaae826fb6ef9f288fad92743fd020840
Author: Pablo Estrada <pa...@apache.org>
AuthorDate: Tue Jan 5 12:34:05 2021 -0800

    Copying Github action into our own repository to comply with Apache security requirements
---
 .github/actions/github-push-action/LICENSE    | 21 +++++++++
 .github/actions/github-push-action/README.md  | 59 ++++++++++++++++++++++++
 .github/actions/github-push-action/action.yml | 30 ++++++++++++
 .github/actions/github-push-action/start.js   | 66 +++++++++++++++++++++++++++
 .github/actions/github-push-action/start.sh   | 28 ++++++++++++
 .github/workflows/build_wheels.yml            |  2 +-
 6 files changed, 205 insertions(+), 1 deletion(-)

diff --git a/.github/actions/github-push-action/LICENSE b/.github/actions/github-push-action/LICENSE
new file mode 100644
index 0000000..3018069
--- /dev/null
+++ b/.github/actions/github-push-action/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019 Adam Dobrawy
+
+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.
diff --git a/.github/actions/github-push-action/README.md b/.github/actions/github-push-action/README.md
new file mode 100644
index 0000000..8cdabfa
--- /dev/null
+++ b/.github/actions/github-push-action/README.md
@@ -0,0 +1,59 @@
+# GitHub Action for GitHub Push
+
+The GitHub Actions for pushing to GitHub repository local changes authorizing using 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@v2
+      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 files
+      run: |
+        git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
+        git config --local user.name "github-actions[bot]"
+        git commit -m "Add changes" -a
+    - name: Push changes
+      uses: ad-m/github-push-action@master
+      with:
+        github_token: ${{ secrets.GITHUB_TOKEN }}
+        branch: ${{ github.ref }}
+```
+
+### Inputs
+
+| name | value | default | description |
+| ---- | ----- | ------- | ----------- |
+| github_token | string | | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. |
+| branch | string | (default) | Destination branch to push changes. Can be passed in using `${{ github.ref }}`. |
+| 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).
+
+## 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.
diff --git a/.github/actions/github-push-action/action.yml b/.github/actions/github-push-action/action.yml
new file mode 100644
index 0000000..b06932b
--- /dev/null
+++ b/.github/actions/github-push-action/action.yml
@@ -0,0 +1,30 @@
+name: 'GitHub Push'
+description: 'Pushing to GitHub repository local changes'
+author: 'ad-m'
+branding:
+  icon: upload-cloud
+  color: green
+inputs:
+  github_token:
+    description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
+    required: true
+  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
+  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: 'node12'
+  main: 'start.js'
diff --git a/.github/actions/github-push-action/start.js b/.github/actions/github-push-action/start.js
new file mode 100644
index 0000000..50c5d25
--- /dev/null
+++ b/.github/actions/github-push-action/start.js
@@ -0,0 +1,66 @@
+'use strict';
+const spawn = require('child_process').spawn;
+const path = require("path");
+const https = require('https');
+
+const get = (url, options = {}) => new Promise((resolve, reject) => https
+    .get(url, options, (res) => {
+        const chunks = [];
+        res.on('data', (chunk) => chunks.push(chunk));
+        res.on('end', () => {
+            const body = Buffer.concat(chunks).toString('utf-8');
+            if (res.statusCode < 200 || res.statusCode > 300) {
+                return reject(Object.assign(
+                    new Error(`Invalid status code '${res.statusCode}' for url '${url}'`),
+                    { res, body }
+                ));
+            }
+            return resolve(body)
+        });
+    })
+    .on('error', reject)
+)
+
+const exec = (cmd, args = [], options = {}) => new Promise((resolve, reject) =>
+    spawn(cmd, args, { stdio: 'inherit', ...options })
+        .on('close', code => {
+            if (code !== 0) {
+                return reject(Object.assign(
+                    new Error(`Invalid exit code: ${code}`),
+                    { code }
+                ));
+            };
+            return resolve(code);
+        })
+        .on('error', reject)
+);
+
+const trimLeft = (value, charlist = '/') => value.replace(new RegExp(`^[${charlist}]*`), '');
+const trimRight = (value, charlist = '/') => value.replace(new RegExp(`[${charlist}]*$`), '');
+const trim = (value, charlist) => trimLeft(trimRight(value, charlist));
+
+const main = async () => {
+    let branch = process.env.INPUT_BRANCH;
+    const repository = trim(process.env.INPUT_REPOSITORY || process.env.GITHUB_REPOSITORY);
+    if (!branch) {
+        const headers = {
+            'User-Agent': 'github.com/ad-m/github-push-action'
+        };
+        if (process.env.GITHUB_TOKEN) headers.Authorization = `token ${process.env.GITHUB_TOKEN}`;
+        const body = JSON.parse(await get(`https://api.github.com/repos/${repository}`, { headers }))
+        branch = body.default_branch;
+    }
+    await exec('bash', [path.join(__dirname, './start.sh')], {
+        env: {
+            ...process.env,
+            INPUT_BRANCH: branch,
+            INPUT_REPOSITORY: repository,
+        }
+    });
+};
+
+main().catch(err => {
+    console.error(err);
+    console.error(err.stack);
+    process.exit(err.code || -1);
+})
diff --git a/.github/actions/github-push-action/start.sh b/.github/actions/github-push-action/start.sh
new file mode 100755
index 0000000..21c3cbe
--- /dev/null
+++ b/.github/actions/github-push-action/start.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+set -e
+
+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 push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;
diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml
index 048e871..6ef55e5 100644
--- a/.github/workflows/build_wheels.yml
+++ b/.github/workflows/build_wheels.yml
@@ -256,7 +256,7 @@ jobs:
           echo "Tagging ${BRANCH_NAME}"
           git tag -f nightly-${BRANCH_NAME} HEAD
       - name: Push tags
-        uses: ad-m/github-push-action@master
+        uses: ./.github/actions/github-push-action
         with:
           github_token: ${{ secrets.GITHUB_TOKEN }}
           tags: true