Skip to content

Commit b8fd91d

Browse files
Update README, description, dependencies, and add example workflows
1 parent 7ddd1ca commit b8fd91d

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ This is set to whether or not the code upload is successful.
8181
If the code upload is not successful, the error message is set to this value.
8282

8383
## Usage and Examples
84-
See the [Examples](https://github.com/optimizely/upload-custom-code-action/tree/master/examples) folder in this repository for example workflows that utilize this action.
84+
See the [Examples](https://github.com/optimizely/upload-custom-code-action/tree/main/examples) folder in this repository for example workflows that utilize this action.
8585

8686
## License
8787
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'Optimizely - Custom Code Uploader'
2-
description: 'A Github Action that enables Optimizely customers to upload custom JS / CSS to their projects.'
2+
description: 'A Github Action that enables Optimizely customers to upload custom JS / CSS to their projects'
33
branding:
44
icon: 'upload-cloud'
55
color: 'blue'

examples/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Example Usage
2+
3+
## `manual.yml`
4+
5+
This is an example workflow where the code upload is manually triggered via the Actions tab in the repository.
6+
7+
## `on-issue-comment.yml`
8+
9+
This is an example workflow that is triggered whenever a comment is made within the repository
10+
(e.g. a comment on a pull request) that contains the keywords "@Upload to Optimizely". When
11+
triggered, an :eyes: reaction is added to the comment.
12+
13+
The results of the upload are appended to the comment noting whether or not the upload was successful.
14+
In the case that an upload was not successful, the error reason is added as well.
15+
* In addition, on successful uploads a :rocket: reaction is added to the comment, whereas in
16+
unsuccessful uploads a :-1: reaction is added.
17+
18+
This particular workflow is highly customizable and in addition to this action uses the
19+
[pull-request-comment-trigger](https://github.com/Khan/pull-request-comment-trigger) and
20+
[create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) actions
21+
to handle the trigger and comment updates respectively.
22+
23+
One could imagine, for example, augmenting this workflow to use the `custom-comment` field to append a comment to
24+
the custom code noting the time that the upload was performed.
25+
26+
Another example is adding an action that can minify JavaScript code to the workflow in order to
27+
minify any code before uploading it to Optimizely.
28+
29+
This is just a couple examples of the near infinite workflows that one could build using this action.

examples/manual.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Manually Triggered Custom Code Upload
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
code-file-path:
7+
description: 'Path from root directory to file with custom code'
8+
required: true
9+
custom-code-level:
10+
description: 'project, experiment, or variation'
11+
required: false
12+
default: 'variation'
13+
custom-code-type:
14+
description: 'custom_code or custom_css'
15+
required: false
16+
default: 'custom_code'
17+
project-id:
18+
description: 'Project ID - required for Project Level Changes'
19+
required: false
20+
experiment-id:
21+
description: 'Experiment ID - required for Experiment / Variation Level Changes'
22+
required: false
23+
variation-id:
24+
description: 'Variation ID - required for Variation Level Changes'
25+
required: false
26+
page-id:
27+
description: 'Page ID - required for Variation Level Changes'
28+
required: false
29+
no-comment:
30+
description: 'No Comment - Whether or not a comment SHOULD NOT be appended to the end of the custom code'
31+
required: false
32+
default: 'false'
33+
custom-comment:
34+
description: 'Custom Comment - A comment to be appended to the end of the custom code'
35+
required: false
36+
default: 'This code was uploaded via the Optimizely Upload Custom Code Github Action.'
37+
fail-silently:
38+
description: 'Fail Silently - When set to true, only print errors in logs but does not fail entire workflow'
39+
required: false
40+
default: 'false'
41+
jobs:
42+
update_experiment_custom_code:
43+
runs-on: ubuntu-latest
44+
name: A job to upload custom code to an Optimizely experiment
45+
steps:
46+
- name: Upload custom code
47+
uses: optimizely/upload-custom-code-action@1.0.0
48+
id: upload-custom-code
49+
with:
50+
optimizely-access-token: ${{ secrets.OPTIMIZELY_API_ACCESS_TOKEN }}
51+
code-file-path: ${{ github.event.inputs.code-file-path }}
52+
custom-code-level: ${{ github.event.inputs.custom-code-level }}
53+
custom-code-type: ${{ github.event.inputs.custom-code-type }}
54+
project-id: ${{ github.event.inputs.project-id }}
55+
experiment-id: ${{ github.event.inputs.experiment-id }}
56+
variation-id: ${{ github.event.inputs.variation-id }}
57+
page-id: ${{ github.event.inputs.page-id }}
58+
no-comment: ${{ github.event.inputs.no-comment }}
59+
custom-comment: ${{ github.event.inputs.custom-comment }}
60+
fail-silently: ${{ github.event.inputs.fail-silently }}
61+
# Use the output from the `upload custom code` step
62+
- name: Get the upload result
63+
run: echo "Was the process was successful? ${{ steps.upload-custom-code.outputs.success }}"

examples/on-issue-comment.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Custom Code Upload on Issue Comment
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
jobs:
7+
update_experiment_custom_code:
8+
runs-on: ubuntu-latest
9+
name: A job to upload custom code to an Optimizely experiment
10+
steps:
11+
- name: Pull Request Comment Trigger
12+
uses: Khan/pull-request-comment-trigger@1.0.0
13+
id: checkForKeyword
14+
with:
15+
trigger: '@Upload to Optimizely'
16+
reaction: eyes
17+
env:
18+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
19+
- name: Upload custom code
20+
if: ${{ steps.checkForKeyword.outputs.triggered == 'true' }}
21+
uses: optimizely/upload-custom-code-action@1.0.0
22+
id: upload-custom-code
23+
with:
24+
optimizely-access-token: ${{ secrets.OPTIMIZELY_API_ACCESS_TOKEN }}
25+
parameters-comment: ${{github.event.comment.body}}
26+
fail-silently: true
27+
- name: Update comment with success notification
28+
if: ${{ steps.upload-custom-code.outputs.success == 'true' }}
29+
uses: peter-evans/create-or-update-comment@v1
30+
with:
31+
comment-id: ${{github.event.comment.id}}
32+
body: |
33+
**--------------**
34+
**Upload Status:** The custom code upload was successful.
35+
reactions: rocket
36+
- name: Update comment with error reason
37+
uses: peter-evans/create-or-update-comment@v1
38+
if: ${{ steps.upload-custom-code.outputs.success != 'true' && steps.checkForKeyword.outputs.triggered == 'true' }}
39+
with:
40+
comment-id: ${{github.event.comment.id}}
41+
body: |
42+
**Upload Status:** The custom code upload was not successful. *Error Message:* ${{steps.upload-custom-code.outputs.error_reason}}
43+
reactions: '-1'

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "upload-custom-code-action",
33
"version": "1.0.0",
4-
"description": "A Github Action that enables Optimizely customers to upload custom JS / CSS to their projects.",
4+
"description": "A Github Action that enables Optimizely customers to upload custom JS / CSS to their projects",
55
"main": "src/index.js",
66
"scripts": {
77
"build": "ncc build src/index.js",
@@ -20,8 +20,7 @@
2020
"homepage": "https://github.com/optimizely/upload-custom-code-action#readme",
2121
"dependencies": {
2222
"@actions/core": "^1.2.4",
23-
"isomorphic-fetch": "^3.0.0",
24-
"node-fetch": "^2.6.1"
23+
"isomorphic-fetch": "^3.0.0"
2524
},
2625
"devDependencies": {
2726
"@vercel/ncc": "^0.25.1",

0 commit comments

Comments
 (0)