Skip to content
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

doc: empty change #17

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: Scheduled Actions

on:
schedule:
- cron: "*/5 * * * *"

jobs:
commitQueue:
runs-on: ubuntu-latest
steps:
# Install dependencies
- name: Install jq
run: sudo apt-get install jq -y
- name: Install Node.js
uses: actions/setup-node@v2-beta
with:
node-version: '12'
- name: Install node-core-utils
run: npm run -g 'https://github.com/mmarchini/node-core-utils#start-ci'
# run: npm run -g node-core-utils

- name: Set variables
run: |
echo "::set-env name=REPOSITORY::$(echo ${{ github.repository }} | cut -d/ -f2)"
echo "::set-env name=OWNER::${{ github.repository_owner }}"

# Get Pull Requests
- name: Get Pull Requests
uses: octokit/graphql-action@v2.x
id: get_mergable_pull_requests
with:
query: |
query release($owner:String!, $repo:String!) {
repository(owner:$owner, name:$repo) {
pullRequests(labels: ["ci-requested"], states: OPEN, last: 100) {
nodes {
number
}
}
}
}
owner: ${{ env.OWNER }}
repo: ${{ env.REPOSITORY }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup node-core-utils
run: |
ncu-config set username ${{ secrets.JENKINS_USER }}
ncu-config set token none
ncu-config set jenkins_token ${{ secrets.JENKINS_TOKEN }}
ncu-config set owner ${{ env.OWNER }}
ncu-config set repo ${{ env.REPOSITORY }}

- name: Start CI
run: ./tools/start-ci.sh $(echo '${{ steps.get_mergable_pull_requests.outputs.data }}' | jq '.repository.pullRequests.nodes | map(.number) | .[]')
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<p align="center">
<a href="https://nodejs.org/">
<img
Expand Down
48 changes: 48 additions & 0 deletions tools/start-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -xe

REQUEST_CI_LABEL='request-ci'
REQUEST_CI_FAILED_LABEL='request-ci-failed'

function issueUrl() {
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}"
}

function labelsUrl() {
echo "$(issueUrl "${1}")/labels"
}

function commentsUrl() {
echo "$(issueUrl "${1}")/comments"
}

for pr in "$@"; do
curl -sL --request DELETE \
--url "$(labelsUrl "$pr")"/"$REQUEST_CI_LABEL" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json'

ci_started=yes
rm -f output;
ncu-ci run "$pr" >output 2>&1 || ci_started=no

if [ "$ci_started" == "no" ]; then
# Do we need to reset?
curl -sL --request PUT \
--url "$(labelsUrl "$pr")" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json' \
--data '{"labels": ["'"${REQUEST_CI_FAILED_LABEL}"'"]}'

jq -n --arg content "<details><summary>Couldn't start CI</summary><pre>$(cat output)</pre></details>" '{body: $content}' > output.json

curl -sL --request POST \
--url "$(commentsUrl "$pr")" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json' \
--data @output.json

rm output.json;
fi
done;