From 418ee20c5a2e8f25b828a8bf3ebf15fd085c2f5a Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 15 Jun 2020 22:54:42 -0500 Subject: [PATCH 1/2] Allow specifying rebuild branch --- .github/workflows/rebuild.yml | 51 +++++++++++++++++++++-------------- make_pipeline.py | 16 +++++++---- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 48adbde8..0aac4ff5 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -7,34 +7,45 @@ on: - created push: status: -env: - GITLAB_TRIGGER: https://gitlab.com/api/v4/projects/19345468/trigger/pipeline - GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} jobs: - RandomRebuild: - if: github.event_name == 'schedule' + TriggerRebuild: + if: github.event_name == 'schedule' || github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '!rebuild') runs-on: ubuntu-latest steps: - run: | + cmd="$(echo '${{ github.event.comment.body }}' | head -n1 | cut -d' ' -f2-)" + while [[ "$cmd" != '' && "$cmd" != '!rebuild' ]]; do + arg="$(echo $cmd | cut -d' ' -f1)" + key="$(echo $arg | cut -d= -f1)" + val="$(echo $arg | cut -d= -f2)" + case "$key" in + branch) + branch="$val" + ;; + file) + folder="$(echo $val | cut -d/ -f1)" + file="$(echo $val | cut -d/ -f2)" + ;; + *) + echo "Unknown command $key" + exit 1 + ;; + esac + if echo "$cmd" | grep -q ' '; then + cmd="$(echo $cmd | cut -d' ' -f2)" + else + cmd="" + fi + done curl --fail \ - -F "token=$GITLAB_TOKEN" \ - -F "ref=master" \ - "$GITLAB_TRIGGER" - ManualRebuild: - if: github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '!rebuild') - runs-on: ubuntu-latest - steps: - - run: | - arg="$(echo '${{ github.event.comment.body }}' | head -n1 | cut -d' ' -f2)" - folder="$(echo $arg | cut -d/ -f1)" - file="$(echo $arg | cut -d/ -f2)" - curl --fail \ - -F "token=$GITLAB_TOKEN" \ + -F "token=${{ secrets.GITLAB_TOKEN }}" \ -F "ref=master" \ + -F "variables[BRANCH]=$branch" \ -F "variables[FOLDER]=$folder" \ -F "variables[FILE]=$file" \ - "$GITLAB_TRIGGER" - - uses: actions/github-script@v2 + https://gitlab.com/api/v4/projects/19345468/trigger/pipeline + - if: github.event_name == 'issue_comment' + uses: actions/github-script@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | diff --git a/make_pipeline.py b/make_pipeline.py index eea01dbb..c325fe3e 100644 --- a/make_pipeline.py +++ b/make_pipeline.py @@ -1,7 +1,7 @@ import os +import sys from random import choice -from sys import stdout from uuid import uuid4 import yaml @@ -21,6 +21,13 @@ tags = ["nvidia"] if file in GPU else [] +branch = os.getenv("BRANCH") +if not branch: + branch = f"rebuild/{str(uuid4())[:8]}" +if not branch.startswith("rebuild/"): + print("Branch name must begin with 'rebuild/'") + sys.exit(1) + script = f""" julia -e ' using Pkg @@ -39,11 +46,10 @@ git config core.sshCommand "ssh -o StrictHostKeyChecking=no -i $SSH_KEY" git config user.name "github-actions[bot]" git config user.email "actions@github.com" -branch="rebuild/{str(uuid4())[:8]}" -git checkout -b "$branch" +git checkout -b {branch} git commit -am "Rebuild tutorials" git remote add github "git@github.com:SciML/DiffEqTutorials.jl.git" -git push github "$branch" +git push github {branch} -f """ pipeline = { @@ -59,4 +65,4 @@ }, } -yaml.dump(pipeline, stdout) +yaml.dump(pipeline, sys.stdout) From a587e9ddc78e7b31f318b2948d480113a5842d32 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Mon, 15 Jun 2020 23:10:57 -0500 Subject: [PATCH 2/2] Parse the comment in a less fragile way This should work on comments with quotes now too. --- .github/workflows/rebuild.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 0aac4ff5..b7517138 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - run: | - cmd="$(echo '${{ github.event.comment.body }}' | head -n1 | cut -d' ' -f2-)" + cmd="$(jq -r .comment.body < "$GITHUB_EVENT_PATH" | head -n1 | cut -d' ' -f2-)" while [[ "$cmd" != '' && "$cmd" != '!rebuild' ]]; do arg="$(echo $cmd | cut -d' ' -f1)" key="$(echo $arg | cut -d= -f1)"