diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index 48adbde8..b7517138 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="$(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)" + 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)