|
| 1 | +name: CI/CD Release Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + |
| 9 | + release: |
| 10 | + types: [published] |
| 11 | + |
| 12 | +jobs: |
| 13 | + publish-docs: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + defaults: |
| 16 | + run: |
| 17 | + shell: bash -l {0} |
| 18 | + timeout-minutes: 20 |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Cache Conda |
| 26 | + uses: actions/cache@v4 |
| 27 | + env: |
| 28 | + # Increase this value to reset cache if deploy/conda-dev-spec.template has not changed in the workflow |
| 29 | + CACHE_NUMBER: 0 |
| 30 | + with: |
| 31 | + path: ~/conda_pkgs_dir |
| 32 | + key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ |
| 33 | + hashFiles('dev-spec.txt') }} |
| 34 | + |
| 35 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 36 | + name: Set up Conda Environment |
| 37 | + uses: conda-incubator/setup-miniconda@v3 |
| 38 | + with: |
| 39 | + activate-environment: "mpas_analysis_ci" |
| 40 | + miniforge-version: latest |
| 41 | + channels: conda-forge |
| 42 | + channel-priority: strict |
| 43 | + auto-update-conda: true |
| 44 | + python-version: ${{ matrix.python-version }} |
| 45 | + |
| 46 | + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} |
| 47 | + name: Install mpas_analysis |
| 48 | + run: | |
| 49 | + git config --global url."https://github.com/".insteadOf "[email protected]:" |
| 50 | + conda create -n mpas_analysis_dev --file dev-spec.txt \ |
| 51 | + python=${{ matrix.python-version }} |
| 52 | + conda activate mpas_analysis_dev |
| 53 | + python -m pip install -vv --no-deps --no-build-isolation -e . |
| 54 | +
|
| 55 | + - name: Build Sphinx Docs |
| 56 | + run: | |
| 57 | + set -e |
| 58 | + conda activate mpas_analysis_dev |
| 59 | + pip check |
| 60 | + mpas_analysis sync diags --help |
| 61 | + cd docs |
| 62 | + sphinx-multiversion . _build/html |
| 63 | + - name: Copy Docs and Commit |
| 64 | + run: | |
| 65 | + set -e |
| 66 | + conda activate mpas_analysis_dev |
| 67 | + pip check |
| 68 | + mpas_analysis sync diags --help |
| 69 | + cd docs |
| 70 | + # gh-pages branch must already exist |
| 71 | + git clone https://github.com/MPAS-Dev/MPAS-Analysis.git --branch gh-pages --single-branch gh-pages |
| 72 | + # Make sure we're in the gh-pages directory. |
| 73 | + cd gh-pages |
| 74 | + # Create `.nojekyll` (if it doesn't already exist) for proper GH Pages configuration. |
| 75 | + touch .nojekyll |
| 76 | + # Add `index.html` to point to the `develop` branch automatically. |
| 77 | + printf '<meta http-equiv="refresh" content="0; url=./develop/index.html" />' > index.html |
| 78 | + # Only replace docs in a directory with the destination branch name with latest changes. Docs for |
| 79 | + # releases should be untouched. |
| 80 | + rm -rf ${{ github.head_ref || github.ref_name }} |
| 81 | + # don't clobber existing release versions (in case we retroactively fixed them) |
| 82 | + cp -r -n ../_build/html/* . |
| 83 | + # Configure git using GitHub Actions credentials. |
| 84 | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 85 | + git config --local user.name "github-actions[bot]" |
| 86 | + # The second command will fail if no changes were present, so we ignore it |
| 87 | + git add . |
| 88 | + git commit -m "Update documentation" -a || true |
| 89 | + - name: Push Changes |
| 90 | + uses: ad-m/github-push-action@master |
| 91 | + with: |
| 92 | + branch: gh-pages |
| 93 | + directory: docs/gh-pages |
| 94 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 95 | + force: true |
| 96 | + |
0 commit comments