North-Seattle-College / ad440-winter2021-thursday-repo

NSC AD 440 Winter 2021 Thursday cohort practicum repo
Apache License 2.0
2 stars 27 forks source link

[TASK] Adjust Github Actions so they run in order #195

Open Dylan-Riley opened 3 years ago

Dylan-Riley commented 3 years ago

Order:

  1. deploy-ui
  2. deploy-functions
  3. artillery-users
  4. artillery-users-user_id
  5. artillery-users-user_id-tasks
  6. artillery-users-user_id-tasks-task_id
  7. slsart-api-users
  8. slsart-api-users-user_id
  9. slsart-api-users-user_id-tasks
  10. slsart-api-users-user_id-tasks-task_id
  11. slsart-UI-users
  12. slsart-UI-users-user_id
  13. slsart-UI-users-user_id-tasks
  14. slsart-UI-users-user_id-tasks-task_id

Many will need to be renamed, a few might need adjusting.

Preliminary research makes it seem there's not a super elegant way to make workflows wait on other workflows.

From https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_run :

workflow_run This event occurs when a workflow run is requested or completed, and allows you to execute a workflow based on the finished result of another workflow. For example, if your pull_request workflow generates build artifacts, you can create a new workflow that uses workflow_run to analyze the results and add a comment to the original pull request.

The workflow started by the workflow_run event is able to access the secrets and write tokens used by the original workflow.

Note: This event will only trigger a workflow run if the workflow file is on the default branch.


Also try to figure out https://github.com/North-Seattle-College/ad440-winter2021-thursday-repo/issues/186

Dylan-Riley commented 3 years ago

Add all artillery and serverless-artillery actions to their own respective workflows?

Can serverless-artillery deploy a single time before doing all eight tests/invokes then do a single remove?

Which of the workflows depend on which other workflows?

Dylan-Riley commented 3 years ago

Find previous issues/PRs for the deploy actions (UI/functions) see exactly what those do, how long they take.

Dylan-Riley commented 3 years ago

Read up on https://github.com/softprops/turnstyle

Looks more like it's used to prevent the same action running in parallel from multiple merges, but it might do

Dylan-Riley commented 3 years ago

Okay, so this is fairly simple using on: repository_dispatch (See here) BUT the workflows need to be in the default branch!

Using

name: foo

on: [push]

jobs:
  workflow1:
    name: workflow 1
    runs-on: ubuntu-latest
    steps:
      - name: checkout code
        uses: actions/checkout@v2
      - name: wait fifteen seconds
        run: |
          echo foo
          sleep 15
      - name: Trigger next workflow
        if: success()
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{ secrets.REPO_GHA_PAT }}
          repository: ${{ github.repository }}
          event-type: trigger-workflow-2
          client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'

and

name: bar

on: 
  repository_dispatch:
    types: [trigger-workflow-2]

jobs:
  workflow2:
    name: workflow 2
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.client_payload.sha }}
      - run: echo bar

I was able to get a proof of concept, but multiple people testing any sweeping changes I make will not work image

Therefore, I have decided only to edit the existing workflows as of 4/MAR/2021 to trigger each other sequentially. I will not be doing any of the extra edits suggested in https://github.com/North-Seattle-College/ad440-winter2021-thursday-repo/issues/195#issuecomment-785697435

Dylan-Riley commented 3 years ago

I also needed to add a secret that is a github Personal Access Token in order to get all the permissions needed. All this token has access to is the repo and workflow scopes, everything else is not included image

Dylan-Riley commented 3 years ago
Previous Workflow Filename Function New Filename Order
artillery-action-users-api.yml test users function with artillery artillery-users.yml 3
artillery-action-users-id-tasks-id.yaml test users/{user_id}/tasks/{task_id} function with artillery artillery-users-user_id-tasks-task_id.yml 6
artillery-test-users-user_id-tasks.yaml test users/{user_id}/tasks function with artillery artillery-users-user_id-tasks.yml 5
artillerytest-performance-user.yml Seemingly was supposed to be a slsart test, horribly broken DELETED N/A
deploy-apis.yaml deploy api functions deploy-functions.yml 2
deploy-ui.yml deploy UI deploy-ui.yml 1
performancetest-users-userID.yaml slsart test users/{user_id} (need to rename and move test script file) slsart-api-users-user_id 8
performancetest.yml unspecified slsart test, would work but doesn't do anything DELETED N/A
serverless-artillery-action-users-id-tasks-api.yml (From https://github.com/North-Seattle-College/ad440-winter2021-thursday-repo/pull/175) slsart test users/{user_id}/tasks slsart-api-users-user_id-tasks.yml 9
serverless-artillery-test-users-api.yml slsart test users slsart-api-users.yml 7
serverless-artilleryreport-users-user_id-tasks.yml Old version of step 9, would have been removed with https://github.com/North-Seattle-College/ad440-winter2021-thursday-repo/pull/175 DELETED N/A
sql-injection-post-users-userid-tasks.yml SQL injection test? Not on my list unchanged last
ui-tests-users.yaml test the UI of users, not a slsart test unchanged tentative 11
Dylan-Riley commented 3 years ago

Only ten working (presumably) workflows in /.github/workflows/ total, two of which aren't technically on my list.

Missing: