-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added workflow and gcp JS client library script with package json #2889
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
Added workflow and gcp JS client library script with package json #2889
Conversation
chriswr95
left a comment
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.
Please also add a detailed description to the PR. What is this code? What purpose does it serve? How did we test it? We also want to communicate that we're raising the PR now so we can code review it, but don't plan on landing the PR until later in the project. Until then, we're hoping it can hang out as a draft. Probably about four weeks time.
| description: 'Classes to test' | ||
| required: false | ||
| PULL_REQUEST_NUMBER_INPUT: | ||
| description: 'Pull request number' |
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.
can you the usage of each of these parameters to the description? for example if this is specified, we will comment a link to the tests results on this pull request.
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.
I added it to the description.
| #Actions secrets (keys) | ||
| PROJECT_ID: ${{ secrets.PROJECT_ID }} | ||
| QUEUE_ID: ${{ secrets.QUEUE_ID }} | ||
| LOCATION: ${{ secrets.LOCATION }} |
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.
what is this?
| QUEUE_ID: ${{ secrets.QUEUE_ID }} | ||
| LOCATION: ${{ secrets.LOCATION }} | ||
| WORKFLOW_URL: ${{ secrets.WORKFLOW_URL }} | ||
| SERVICE_ACCOUNT_EMAIL: ${{ secrets.SERVICE_ACCOUNT_EMAIL }} |
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.
why is this needed?
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.
I already updated the description of the draft PR to explain why we need each of those variables.
| - run: npm i yenv | ||
| - run: npm i uuid | ||
|
|
||
| - id: 'auth' |
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.
this is very cool
google_cloud_http_target_task.js
Outdated
| const serviceAccountEmail = parsedDocument.SERVICE_ACCOUNT_EMAIL; | ||
|
|
||
| // Construct payload | ||
| const payloadStructure = { |
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.
please format this like
const payloadStructure = {
val1: var1,
val2: var2,
...
};
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.
Done.
google_cloud_http_target_task.js
Outdated
| console.log(`Created task ${name}`); | ||
| console.log(`Your job id is: ${jobId}`); | ||
| } | ||
| createHttpTaskWithToken(); No newline at end of file |
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.
let's chat in person about refactoring this script just a bit, overall it looks pretty good.
| with: | ||
| node-version: '14' | ||
| - run: npm install | ||
| - run: npm i yenv |
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.
if you add yenv to your package.json, can you skip this extra step, as it will be installed during npm install?
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.
Done, I added it to the package.json instead.
package.json
Outdated
| "devDependencies": { | ||
| "chai": "^4.2.0", | ||
| "mocha": "^8.0.0", | ||
| "uuid": "^8.0.0" |
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.
is uuid only a dev dependency? I think it should be a regular dependency. Similarly, do you need mocha and chai? I we don't have any tests for this code.
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.
Yes, I have already updated this file. We don't need mocha an chai.
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.
I am not really comfortable with having this in the root folder. Can we move this file into the .github/workflow directory?
The reason is security and maintenance: this is not s JS project and we don't depend on JS libraries for the actual lib we publish. This should be clearly only used for the github workflow
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.
Thanks for that Andi! I moved it into workflows folder.
google_cloud_http_target_task.js
Outdated
| @@ -0,0 +1,63 @@ | |||
| const {CloudTasksClient} = require('@google-cloud/tasks'); | |||
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.
this probably shouldn't live at the root level, maybe instead at .github/workflow-scripts?
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.
Done. I added it inside .github/workflow
google_cloud_http_target_task.js
Outdated
| const yenv = require('yenv') | ||
| const { v4: uuidv4 } = require('uuid'); | ||
| const fs = require('fs') | ||
| const os = require('os'); |
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.
is this used anywhere?
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.
No, I have already fixed it in the new commit.
| const yenv = require('yenv') | ||
| const { v4: uuidv4 } = require('uuid'); | ||
|
|
||
| const parsedDocument = yenv('.github/workflows/gql-perf-arch-github_workflow.yml') |
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.
Is it possible to use process.env.COMMIT_HASH and likewise for all other env variables? we might not need yenv dependency.
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.
Yes, you were right. The change is done.
chriswr95
left a comment
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.
This code looks much tighter.
NIT: For your PR description, you are now a little bit too verbose. Aim for clear and succinct language. You should spend 20 minutes writing the description so that a reviewer can read it in one minute. Using Markdown also helps to structure longer messages. No need to change anything, just leaving this for the future :)
Approved pending a final nit comment.
| } | ||
|
|
||
| async function createHttpTaskWithToken() { | ||
| const payloadStructure = constructPayload(); |
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.
you can wrap lines 58 - 61 into yet another helper function createRequest() which returns the request.
| description: 'Pull request number' | ||
| required: false | ||
| env: | ||
| #Actions secrets (keys) |
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.
can remove this comment.
package.json
Outdated
| "dependencies": { | ||
| "@google-cloud/tasks": "^3.0.0", | ||
| "body-parser": "^1.18.3", | ||
| "express": "^4.16.3", |
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.
do we need express here? I don't think we are running any server, right?
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.
True, we don't need express. Already removed it.
package.json
Outdated
| "name": "appengine-cloudtasks", | ||
| "description": "Google App Engine Cloud Tasks example.", | ||
| "license": "Apache-2.0", | ||
| "author": "Google Inc.", |
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.
I don't think this is right. We could just remove author, license, descp etc as we don;t plan to publish this
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.
True, I removed those fields.
The purpose of this draft PR is to add a Github actions workflow that will be executed every time there is a push to this repository or when manually triggering it through Github UI.
The workflow will run a Javascript Google Cloud Client library file that will create and send a task to a Google Cloud Tasks Queue and will then forward it to a Google Cloud Workflow that will execute the test runner.
This draft PR consists on adding 3 new files:
*To verify the reliability of the workflow we have first built and tested a fully functional prototype that works as expected.
Considerations:
a) In order to execute the workflow we need credentials and other information (i.e. the name of our project in Google Cloud Platform) that we will provide, but must remain confidential, therefore, those should be stored as Github Actions secrets and are the following:
GOOGLE_APPLICATION_CREDENTIALS -> This is a JSON file that will authenticate our GCP account at every execution.
LOCATION -> Location where the Queue is running.
PROJECT_ID -> The name of the GCP project where the Queue is stored.
QUEUE_ID -> The name of the Queue where the task will be sent.
SERVICE_ACCOUNT_ROLE -> The GCP account that contains the permissions and roles to manage the Queue.
WORKFLOW_URL -> The endpoint to which the Queue will send an http request to forward the task to a GCP Workflow.
b) The purpose of triggering manually the workflow is to run personalized tests, so 3 inputs will we requested:
- Commit hash. (required)
- Classes to test. (optional)
- Pull request number. (optional)
*If the optional fields are left empty, all tests will be executed on that specific commit.
We will comment a link to the tests results on this pull request.
c) Since we are still working on the test runner this draft PR is intended just for code reviews purposes. We plan on landing the PR once the project is on a working state, probably about four weeks time.