-
Notifications
You must be signed in to change notification settings - Fork 79
feat(github-actions): autoremove preview labels in pull request labeling action #3945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,56 +32,28 @@ inputs: | |
| Project-relative path to the directory contents that should be deployed. | ||
| This is usually the distribution directory, like `dist/my-app/`. | ||
|
|
||
| angular-robot-key: | ||
| description: 'The private key for the Angular Robot Github app.' | ||
| required: true | ||
|
|
||
| triggering-label: | ||
| description: Label that triggers the preview deployment. | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Automatically remove preview trigger label if PR author is not a Googler | ||
| if: contains(github.event.pull_request.labels.*.name, inputs.triggering-label) | ||
| shell: bash | ||
| env: | ||
| INPUT_ANGULAR-ROBOT-KEY: '${{inputs.angular-robot-key}}' | ||
| run: | | ||
| node ${{github.action_path}}/remove-preview-label.js \ | ||
| '${{inputs.pull-number}}' \ | ||
| '${{inputs.triggering-label}}' | ||
|
|
||
| - name: Copying artifact to temp directory to allow for metadata injection. | ||
| id: copy | ||
| if: contains(github.event.pull_request.labels.*.name, inputs.triggering-label) | ||
| shell: bash | ||
| env: | ||
| DEPLOY_DIR_INPUT: ${{inputs.deploy-directory}} | ||
| run: | | ||
| dir="$RUNNER_TEMP/pack-and-upload-tmp-dir" | ||
| rm -rf "$dir" | ||
| cp -R "$DEPLOY_DIR_INPUT" "$dir" | ||
| dir="$RUNNER_TEMP/pack-and-upload-tmp-dir/" | ||
| cp -R "${{inputs.deploy-directory}}" "$dir" | ||
| chmod -R u+w "$dir" | ||
| echo "deploy-dir=$dir" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Injecting artifact metadata | ||
| if: contains(github.event.pull_request.labels.*.name, inputs.triggering-label) | ||
| shell: bash | ||
| env: | ||
| DEPLOY_DIR: ${{steps.copy.outputs.deploy-dir}} | ||
| PULL_NUMBER: ${{inputs.pull-number}} | ||
| BUILD_REVISION: ${{inputs.artifact-build-revision}} | ||
| run: | | ||
| node ${{github.action_path}}/inject-artifact-metadata.js \ | ||
| "$DEPLOY_DIR" \ | ||
| "$PULL_NUMBER" \ | ||
| "$BUILD_REVISION" | ||
| '${{steps.copy.outputs.deploy-dir}}' \ | ||
| '${{inputs.pull-number}}' \ | ||
| '${{inputs.artifact-build-revision}}' | ||
|
Comment on lines
47
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directly interpolating GitHub Actions expressions like If any of these inputs contain a single quote (e.g., To prevent command injection, you should always pass these values to the step via environment variables and reference them as shell variables (e.g., - name: Injecting artifact metadata
shell: bash
env:
DEPLOY_DIR: ${{steps.copy.outputs.deploy-dir}}
PULL_NUMBER: ${{inputs.pull-number}}
BUILD_REVISION: ${{inputs.artifact-build-revision}}
run: |
node ${{github.action_path}}/inject-artifact-metadata.js \
"$DEPLOY_DIR" \
"$PULL_NUMBER" \
"$BUILD_REVISION" |
||
|
|
||
| - name: Creating compressed tarball of artifact | ||
| id: pack | ||
| if: contains(github.event.pull_request.labels.*.name, inputs.triggering-label) | ||
| shell: bash | ||
| run: | | ||
| pkg="$RUNNER_TEMP/deploy-artifact.tar.gz" | ||
|
|
@@ -90,7 +62,6 @@ runs: | |
| echo "artifact-path=$pkg" >> $GITHUB_OUTPUT | ||
|
|
||
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| if: contains(github.event.pull_request.labels.*.name, inputs.triggering-label) | ||
| with: | ||
| name: '${{inputs.workflow-artifact-name}}' | ||
| path: '${{steps.pack.outputs.artifact-path}}' | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two issues in this step:
rm -rf "$dir"can cause issues on persistent or self-hosted runners. Ifpack-and-upload-tmp-diralready exists,cp -Rwill copy the source directory into it, creating a nested folder (e.g.,pack-and-upload-tmp-dir/my-app/...) instead of placing the files at the root.${{inputs.deploy-directory}}into the shell script is a security risk (CWE-94). If the input contains shell metacharacters (like backticks or$()), they will be executed.Using environment variables and restoring the
rm -rfcleanup solves both issues safely.