Skip to content

Commit

Permalink
slo check allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriya Popova committed Aug 9, 2023
1 parent 870a55f commit ea975eb
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion .github/workflows/slo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,85 @@ on:
workflow_dispatch:

jobs:
check-running-allowed:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.check-ownership-membership.outputs.result }}
steps:
- id: check-ownership-membership
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// This is used primarily in forks. Repository owner
// should be allowed to run anything.
const userLogin = context.payload.pull_request.user.login;
// How to interpret membership status code:
// https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
const isOrgMember = async function () {
try {
const response = await github.rest.orgs.checkMembershipForUser({
org: context.payload.organization.login,
username: userLogin,
});
return response.status == 204;
} catch (error) {
if (error.status && error.status == 404) {
return false;
}
throw error;
}
}
if (context.payload.repository.owner.login == userLogin) {
return true;
}
if (await isOrgMember()) {
return true;
}
const labels = context.payload.pull_request.labels;
const okToTestLabel = labels.find(
label => label.name == 'ok-to-test'
);
return okToTestLabel !== undefined;
- name: comment-if-waiting-on-ok
if: steps.check-ownership-membership.outputs.result == 'false' &&
github.event.action == 'opened'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Hi! Thank you for contributing!\nThe tests on this PR will run after a maintainer adds an `ok-to-test` label to this PR manually. Thank you for your patience!'
});
- name: cleanup-test-label
uses: actions/github-script@v6
with:
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
const labelToRemove = 'ok-to-test';
try {
const result = await github.rest.issues.removeLabel({
owner,
repo,
issue_number: prNumber,
name: labelToRemove
});
} catch(e) {
// ignore the 404 error that arises
// when the label did not exist for the
// organization member
console.log(e);
}
test-slo:
needs:
- check-running-allowed
concurrency:
group: slo-${{ github.ref }}
if: (!contains(github.event.pull_request.labels.*.name, 'no slo'))
Expand All @@ -22,9 +100,11 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
if: ${{ secrets.SLO_DOCKER_REPO != 0 }}

- name: Run SLO
uses: ydb-platform/slo-tests@js-version
if: ${{ secrets.SLO_DOCKER_REPO != 0 }}
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KUBECONFIG_B64: ${{ secrets.SLO_KUBE_CONFIG }}
Expand All @@ -49,7 +129,7 @@ jobs:
workload_build_options0: -f Dockerfile

- uses: actions/upload-artifact@v3
if: always()
if: ${{ secrets.SLO_DOCKER_REPO != 0 }}
with:
name: slo-logs
path: logs/

0 comments on commit ea975eb

Please sign in to comment.