diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml new file mode 100644 index 00000000000..696ec1ff911 --- /dev/null +++ b/.github/workflows/build-docs.yml @@ -0,0 +1,169 @@ +# For more information about TARDIS pipelines, please refer to: +# +# https://tardis-sn.github.io/tardis/development/continuous_integration.html + +name: build-docs + +on: + + push: + branches: + - master + + pull_request_target: + branches: + - master + + types: + - opened + - reopened + - synchronize + - labeled # requires the `build-docs` label + + workflow_dispatch: # manual trigger + +env: + DEPLOY_BRANCH: gh-pages # deployed docs branch + ROOT_REDIRECT: latest # https://tardis-sn.github.io/tardis/latest + +concurrency: + group: build-docs-${{ github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash -l {0} + +jobs: + build: + + if: github.event_name == 'push' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'pull_request_target' && + contains(github.event.pull_request.labels.*.name, 'build-docs')) + + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + if: github.event_name != 'pull_request_target' + + - name: Checkout pull/${{ github.event.number }} + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + if: github.event_name == 'pull_request_target' + + - name: Setup environment + uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-variant: Mambaforge + miniforge-version: latest + environment-file: tardis_env3.yml + activate-environment: tardis + use-mamba: true + + - name: Install package + run: pip install -e . + + - name: Build documentation + run: cd docs/ && make html + + - name: Set destination directory + run: | + BRANCH=$(echo ${GITHUB_REF#refs/heads/}) + if [[ $EVENT == push ]] || [[ $EVENT == workflow_dispatch ]]; then + + if [[ $BRANCH == $DEFAULT ]]; then + echo "DEST_DIR=latest" >> $GITHUB_ENV + else + echo "DEST_DIR=branch/$BRANCH" >> $GITHUB_ENV + fi + + elif [[ $EVENT == pull_request_target ]]; then + echo "DEST_DIR=pull/$PR" >> $GITHUB_ENV + + else + echo "Unexpected event trigger $EVENT" + exit 1 + + fi + + cat $GITHUB_ENV + env: + DEFAULT: ${{ github.event.repository.default_branch }} + EVENT: ${{ github.event_name }} + PR: ${{ github.event.number }} + + - name: Deploy ${{ env.DEST_DIR }} + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.BOT_TOKEN }} + publish_branch: ${{ env.DEPLOY_BRANCH }} + publish_dir: ./docs/_build/html + destination_dir: ${{ env.DEST_DIR }} + user_name: 'TARDIS Bot' + user_email: 'tardis.sn.bot@gmail.com' + + - name: Redirect root + run: | + mkdir redirects && cd redirects + echo '' >> index.html + echo ' ' >> index.html + echo '' >> index.html + + - name: Deploy redirect + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.BOT_TOKEN }} + publish_branch: ${{ env.DEPLOY_BRANCH }} + publish_dir: ./redirects + keep_files: true + user_name: 'TARDIS Bot' + user_email: 'tardis.sn.bot@gmail.com' + + - name: Find comment + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ github.event.number }} + body-includes: Hi, human. + if: always() && github.event_name == 'pull_request_target' + + - name: Post comment (success) + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.BOT_TOKEN }} + issue-number: ${{ github.event.number }} + comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace + body: | + *\*beep\* \*bop\** + + Hi, human. + + The **`${{ github.workflow }}`** workflow has **succeeded** :heavy_check_mark: + + [**Click here**](${{ env.URL }}) to see your results. + env: + URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pull/${{ github.event.number }}/index.html + if: success() && github.event_name == 'pull_request_target' + + - name: Post comment (failure) + uses: peter-evans/create-or-update-comment@v1 + with: + token: ${{ secrets.BOT_TOKEN }} + issue-number: ${{ github.event.number }} + comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace + body: | + *\*beep\* \*bop\** + + Hi, human. + + The **`${{ github.workflow }}`** workflow has **failed** :x: + + [**Click here**](${{ env.URL }}) to see the build log. + env: + URL: https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}?check_suite_focus=true + if: failure() && github.event_name == 'pull_request_target' diff --git a/.github/workflows/clean-docs.yml b/.github/workflows/clean-docs.yml new file mode 100644 index 00000000000..738270cbe7b --- /dev/null +++ b/.github/workflows/clean-docs.yml @@ -0,0 +1,64 @@ +# For more information about TARDIS pipelines, please refer to: +# +# https://tardis-sn.github.io/tardis/development/continuous_integration.html + +name: clean-docs + +on: + + delete: + branches: # remove deleted branches + - '*' + + pull_request_target: # remove closed or merged pull requests + branches: + - '*' + types: + - closed + +env: + DEPLOY_BRANCH: gh-pages # deployed docs branch + +jobs: + clean: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + + - name: Set folder to delete + run: | + if [[ $EVENT == delete ]]; then + echo "DEST_DIR=$EVENT_TYPE/$EVENT_REF" >> $GITHUB_ENV + + elif [[ $EVENT == pull_request_target ]]; then + echo "DEST_DIR=pull/$PR" >> $GITHUB_ENV + + else + echo "Unexpected event trigger $EVENT" + exit 1 + + fi + cat $GITHUB_ENV + env: + PR: ${{ github.event.number }} + EVENT: ${{ github.event_name }} + EVENT_REF: ${{ github.event.ref }} + EVENT_TYPE: ${{ github.event.ref_type }} + + - name: Clean ${{ env.DEST_DIR }} + run: | + git fetch origin ${{ env.DEPLOY_BRANCH }} + git checkout ${{ env.DEPLOY_BRANCH }} + git config user.name "TARDIS Bot" + git config user.email tardis.sn.bot@gmail.com + + if [[ -d $DEST_DIR ]]; then + git rm -rf $DEST_DIR + git commit -m "clean $DEST_DIR" + git push + + else + echo "$DEST_DIR does not exist" + + fi diff --git a/.github/workflows/documentation-build.yml b/.github/workflows/documentation-build.yml deleted file mode 100644 index 49481fdb032..00000000000 --- a/.github/workflows/documentation-build.yml +++ /dev/null @@ -1,45 +0,0 @@ -# For more information on how to use this template please refer to: -# http://tardis-sn.github.io/tardis/development/continuous_integration.html - -name: docs - -on: - push: - branches: - - master - - workflow_dispatch: # Manual trigger - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Setup environment - uses: conda-incubator/setup-miniconda@v2 - with: - miniforge-variant: Mambaforge - miniforge-version: latest - environment-file: tardis_env3.yml - activate-environment: tardis - use-mamba: true - - - name: Install TARDIS - shell: bash -l {0} - run: python setup.py install - - - name: Build Sphinx Documentation - shell: bash -l {0} - run: cd docs/; make html CORES=auto - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: docs/_build/html/ - publish_branch: gh-pages - force_orphan: true diff --git a/.github/workflows/documentation-preview.yml b/.github/workflows/documentation-preview.yml deleted file mode 100644 index b0d86aa2ef3..00000000000 --- a/.github/workflows/documentation-preview.yml +++ /dev/null @@ -1,60 +0,0 @@ -# For more information on how to use this pipeline please refer to: -# - http://tardis-sn.github.io/tardis/development/continuous_integration.html -# - https://tardis-sn.github.io/tardis/development/documentation_preview.html - -name: docs-preview - -on: - push: - -jobs: - build: - - # This workflow will be triggered: - # - # 1. Only on forks, never on main repository. - # 2. If the branch name contains the word `doc`. - # 3. If the commit message includes the a valid tag. - - if: github.repository_owner != 'tardis-sn' && ( - contains(github.ref, 'doc') || - contains(github.event.head_commit.message, '[build docs]') || - contains(github.event.head_commit.message, '[build_docs]') || - contains(github.event.head_commit.message, '[build doc]') || - contains(github.event.head_commit.message, '[build_doc]')) - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Setup environment - uses: conda-incubator/setup-miniconda@v2 - with: - miniforge-variant: Mambaforge - miniforge-version: latest - environment-file: tardis_env3.yml - activate-environment: tardis - use-mamba: true - - - name: Install package - shell: bash -l {0} - run: python setup.py install - - - name: Build documentation - shell: bash -l {0} - run: cd docs/; make html CORES=auto - - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: extract_branch - - - name: Deploy site - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_branch: gh-pages - publish_dir: docs/_build/html/ - destination_dir: branch/${{ steps.extract_branch.outputs.branch }}