diff --git a/.github/workflows/rebuild.yml b/.github/workflows/rebuild.yml index b7517138..78f6af17 100644 --- a/.github/workflows/rebuild.yml +++ b/.github/workflows/rebuild.yml @@ -1,4 +1,4 @@ -name: Rebuild Tutorials +name: Rebuild Content on: schedule: - cron: 0 0 */3 * * @@ -7,81 +7,13 @@ on: - created push: status: +env: + GITLAB_PROJECT: ${{ secrets.GITLAB_PROJECT }} + GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} jobs: - TriggerRebuild: - if: github.event_name == 'schedule' || github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '!rebuild') + 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=${{ secrets.GITLAB_TOKEN }}" \ - -F "ref=master" \ - -F "variables[BRANCH]=$branch" \ - -F "variables[FOLDER]=$folder" \ - -F "variables[FILE]=$file" \ - https://gitlab.com/api/v4/projects/19345468/trigger/pipeline - - if: github.event_name == 'issue_comment' - uses: actions/github-script@v2 + - uses: SciML/RebuildAction@master with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - github.reactions.createForIssueComment({ - ...context.repo, - comment_id: context.payload.comment.id, - content: "+1", - }) - OpenPR: - if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/rebuild/') - runs-on: ubuntu-latest - steps: - - uses: actions/github-script@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - github.pulls.create({ - ...context.repo, - title: "Rebuild tutorials", - head: "${{ github.ref }}".slice(11), - base: "master", - }) - FixStatus: - if: github.event_name == 'status' && github.event.context == 'ci/gitlab/gitlab.com' && github.event.state == 'failure' - runs-on: ubuntu-latest - steps: - # TODO: Replace this SHA with a tag when the next version is released. - - uses: actions/github-script@82b33c82ef5e155cb8e0de0862e5dbde0cd451eb - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - github.repos.createCommitStatus({ - ...context.repo, - sha: context.payload.sha, - state: "success", - context: context.payload.context, - description: "This status can be ignored", - target_url: context.payload.target_url, - }) + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd3846ce..3b9de975 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,25 +1,6 @@ -stages: - - setup - - rebuild - -setup: - stage: setup - only: - - triggers - image: python - script: | - pip install pyyaml - python make_pipeline.py > rebuild.yml - artifacts: - paths: - - rebuild.yml - -rebuild: - stage: rebuild - trigger: - include: - - artifact: rebuild.yml - job: setup - strategy: depend - variables: # TODO: Delete after JuliaGPU/gitlab-ci#20 - JULIA_PROJECT: "@." +include: https://raw.githubusercontent.com/SciML/RebuildAction/master/rebuild.yml +variables: + CONTENT_DIR: tutorials + EXCLUDE: exercises/02-workshop_solutions, models/06-pendulum_bayesian_inference + NEEDS_GPU: advanced/01-beeler_reuter + GITHUB_REPOSITORY: SciML/DiffEqTutorials.jl diff --git a/make_pipeline.py b/make_pipeline.py deleted file mode 100644 index c325fe3e..00000000 --- a/make_pipeline.py +++ /dev/null @@ -1,68 +0,0 @@ -import os -import sys - -from random import choice -from uuid import uuid4 - -import yaml - -GPU = {"01-beeler-reuter.jmd"} -LONG = {"02-workshop_solutions.jmd", "06-pendulum_bayesian_inference.jmd"} - -cwd = os.getcwd() -os.chdir("tutorials") -folder = os.getenv("FOLDER") -if not folder: - folder = choice([d for d in os.listdir() if os.path.isdir(d)]) -file = os.getenv("FILE") -if not file: - file = choice([f for f in os.listdir(folder) if f.endswith(".jmd") and f not in LONG]) -os.chdir(cwd) - -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 - Pkg.instantiate() - using DiffEqTutorials: weave_file - weave_file("{folder}", "{file}")' - -if [[ -z "$(git status -suno)" ]]; then - echo "No changes" - exit 0 -fi - -k="$(cat $SSH_KEY)" -echo "$k" > "$SSH_KEY" -chmod 400 "$SSH_KEY" -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" -git checkout -b {branch} -git commit -am "Rebuild tutorials" -git remote add github "git@github.com:SciML/DiffEqTutorials.jl.git" -git push github {branch} -f -""" - -pipeline = { - "include": "https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v6.yml", - "rebuild": { - "extends": ".julia:1.4", - "variables": { - "CI_APT_INSTALL": "git python3-dev texlive-science texlive-xetex", - "JULIA_NUM_THREADS": 4, - }, - "tags": tags, - "script": script, - }, -} - -yaml.dump(pipeline, sys.stdout)