Skip to content

Commit

Permalink
ci: Tests pass gh action (#394)
Browse files Browse the repository at this point in the history
* starts working on action

* updates changelog

Co-authored-by: Rishabh <[email protected]>
  • Loading branch information
rishabhpoddar and Rishabh authored Mar 19, 2022
1 parent c6df7f0 commit 9f545ef
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/helpers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
14 changes: 14 additions & 0 deletions .github/helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "helpers",
"version": "1.0.0",
"description": "",
"main": "test-pass-check-pr.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.26.1"
}
}
40 changes: 40 additions & 0 deletions .github/helpers/test-pass-check-pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { default: axios } = require("axios");

let thisRunId = process.env.RUN_ID;
thisRunId = thisRunId.trim();

axios.get(`https://api.github.com/repos/${process.env.REPO}/actions/runs?branch=${process.env.BRANCH}`).then(async result => {
let data = result.data;
let passed = false;
let currentSHA = undefined;

data.workflow_runs.forEach(run => {
if ((run.id + "") === thisRunId) {
currentSHA = run.head_sha;
}
});

if (currentSHA !== undefined) {
for (let i = 0; i < data.workflow_runs.length; i++) {
let run = data.workflow_runs[i];
if (run.head_sha === currentSHA) {
// here we have all the jobs that have run on this commit.
let workflow_id = run.workflow_id;
let workflow = await axios.get(`https://api.github.com/repos/${process.env.REPO}/actions/workflows/${workflow_id}`);
let workflowData = workflow.data;
if (workflowData.path === ".github/workflows/tests.yml") {
if (run.conclusion === "success") {
passed = true;
break;
}
}
}
}
}

if (!passed) {
console.log("You need to trigger the \"Run tests\" github action and make that succeed.\n\nSee https://github.com/supertokens/supertokens-core/blob/master/CONTRIBUTING.md#using-github-actions\n\nOnce successful, re-run this action.")
}

process.exit(passed ? 0 : 1);
})
20 changes: 20 additions & 0 deletions .github/workflows/tests-pass-check-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Check if \"Run tests\" action succeeded"

on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize

jobs:
pr-run-test-action:
name: Check if "Run tests" action succeeded
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: node install
run: cd ./.github/helpers && npm i
- name: Calling github API
run: cd ./.github/helpers && REPO=${{ github.repository }} RUN_ID=${{ github.run_id }} BRANCH=${{ github.head_ref }} JOB_ID=${{ github.job }} node test-pass-check-pr.js
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]
- Adds github action for running tests against in memory db.
- Adds github action for checking if "Run tests" action was completed (to run in PRs)

## [3.11.0] - 2022-03-19
### Changes
Expand Down

0 comments on commit 9f545ef

Please sign in to comment.