From c00109bdc4dab81f69dce3d4a1bda4f925d7cc86 Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Thu, 10 Oct 2024 14:59:08 -0700 Subject: [PATCH 1/5] Remove azure pipelines workflow --- azure-pipelines.yml | 190 -------------------------------------------- 1 file changed, 190 deletions(-) delete mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 38f423a2b..000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,190 +0,0 @@ - -trigger: - branches: - include: - - main - - develop - tags: - include: - - '*' - -pr: - branches: - include: - - main - - develop - -jobs: -- job: - displayName: linux - pool: - vmImage: 'ubuntu-latest' - strategy: - matrix: - Python310: - python.version: '3.10' - Python311: - python.version: '3.11' - Python312: - python.version: '3.12' - - steps: - - bash: echo "##vso[task.prependpath]$CONDA/bin" - displayName: Add conda to PATH - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda config --add channels conda-forge - conda config --set channel_priority strict - conda create --yes --name build_env conda-build - displayName: Create build environment - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate build_env - conda build -m "ci/python${PYTHON_VERSION}.yaml" "ci/recipe" - displayName: Build MPAS-Analysis - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate - conda create --yes --quiet --name mpas \ - -c ${CONDA_PREFIX}/envs/build_env/conda-bld/ \ - python=$PYTHON_VERSION mpas-analysis pytest - displayName: Create Anaconda mpas environment - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate mpas - pytest --pyargs mpas_analysis - displayName: pytest - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate - conda create --yes --quiet --name docs \ - -c ${CONDA_PREFIX}/envs/build_env/conda-bld/ \ - python=$PYTHON_VERSION mpas-analysis sphinx mock sphinx_rtd_theme \ - tabulate "m2r2>=0.3.3" "mistune<2" - condition: eq(variables['python.version'], '3.10') - displayName: Create Anaconda docs environment - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate docs - - echo "source branch: $(Build.SourceBranch)" - echo "repository: $(Build.Repository.Name)" - - tag=$(git describe --tags $(git rev-list --tags --max-count=1)) - echo "tag: $tag" - - version=`python -c "import mpas_analysis; print(mpas_analysis.__version__)"` - echo "version: $version" - - REPO_PATH=$PWD - - if [[ "$(Build.SourceBranch)" == "refs/heads/develop" ]]; then - export DOCS_VERSION="latest" - deploy=True - elif [[ "$(Build.SourceBranch)" == "refs/heads/main" ]]; then - export DOCS_VERSION="stable" - deploy=True - elif [[ "$(Build.SourceBranch)" == refs/tags/* ]]; then - # this is a tag build - export DOCS_VERSION="$tag" - deploy=True - else - DOCS_VERSION="$version" - export DOCS_VERSION - deploy=False - fi - echo "Docs version: $DOCS_VERSION" - echo "Deploy to gh-pages? $deploy" - cd docs || exit 1 - make html - - cd "$REPO_PATH" || exit 1 - - if [[ "$deploy" == "True" ]]; then - PUBLICATION_BRANCH=gh-pages - # Checkout the branch - pushd $HOME || exit 1 - git clone --branch=$PUBLICATION_BRANCH https://$(GitHubToken)@github.com/$(Build.Repository.Name) publish - cd publish || exit 1 - - # Update pages - if [[ -d "$DOCS_VERSION" ]]; then - git rm -rf "$DOCS_VERSION" > /dev/null - fi - mkdir "$DOCS_VERSION" - cp -r "$REPO_PATH"/docs/_build/html/* "$DOCS_VERSION" - # Commit and push latest version - git add . - if git diff-index --quiet HEAD; then - echo "No changes in the docs." - else - git config --local user.name "Azure Pipelines" - git config --local user.email "azuredevops@microsoft.com" - git commit -m "[skip ci] Update $DOCS_VERSION" - git push -fq origin $PUBLICATION_BRANCH - fi - popd || exit 1 - fi - condition: eq(variables['python.version'], '3.10') - displayName: build and deploy docs - -- job: - displayName: xarray-main - pool: - vmImage: 'ubuntu-latest' - strategy: - matrix: - Python310: - python.version: '3.11' - - steps: - - bash: echo "##vso[task.prependpath]$CONDA/bin" - displayName: Add conda to PATH - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda config --add channels conda-forge - conda config --set channel_priority strict - conda create --yes --name build_env conda-build - displayName: Create build environment - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate build_env - # workaround based on recent failures - rm /usr/share/miniconda/pkgs/cache/*.json - conda build -m "ci/python${PYTHON_VERSION}.yaml" "ci/recipe" - displayName: Build MPAS-Analysis - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate - conda create --yes --quiet --name mpas \ - -c ${CONDA_PREFIX}/envs/build_env/conda-bld/ \ - python=$PYTHON_VERSION mpas-analysis pytest - conda activate mpas - pip install git+https://github.com/pydata/xarray.git - - displayName: Create Anaconda mpas environment - - - bash: | - set -e - eval "$(conda shell.bash hook)" - conda activate mpas - pytest --pyargs mpas_analysis - displayName: pytest From dd5f790707f2cfad626aa8054781b7f677849b16 Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Thu, 10 Oct 2024 14:59:58 -0700 Subject: [PATCH 2/5] Add gh-actions build workflow --- .github/workflows/build_workflow.yml | 92 ++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/build_workflow.yml diff --git a/.github/workflows/build_workflow.yml b/.github/workflows/build_workflow.yml new file mode 100644 index 000000000..687632e02 --- /dev/null +++ b/.github/workflows/build_workflow.yml @@ -0,0 +1,92 @@ +name: CI/CD Build Workflow + +on: + push: + branches: + - main + - develop + + pull_request: + branches: + - main + - develop + + workflow_dispatch: + +env: + CANCEL_OTHERS: false + PATHS_IGNORE: '["**/README.md", "**/docs/**"]' + +jobs: + build: + name: test mpas_analysis - python ${{ matrix.python-version }} + runs-on: ubuntu-latest + timeout-minutes: 20 + defaults: + run: + shell: bash -l {0} + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12"] + steps: + - id: skip_check + uses: fkirc/skip-duplicate-actions@master + with: + cancel_others: ${{ env.CANCEL_OTHERS }} + paths_ignore: ${{ env.PATHS_IGNORE }} + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + uses: actions/checkout@v4 + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Cache Conda + uses: actions/cache@v4 + env: + # Increase this value to reset cache if conda-dev-spec.template has not changed in the workflow + CACHE_NUMBER: 0 + with: + path: ~/conda_pkgs_dir + key: + ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ + hashFiles('dev-spec.txt,setup.py') }} + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Set up Conda Environment + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: "mpas_analysis_ci" + miniforge-version: latest + channels: conda-forge + channel-priority: strict + auto-update-conda: true + python-version: ${{ matrix.python-version }} + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Install mpas_analysis + run: | + conda create -n mpas_analysis_dev --file dev-spec.txt \ + python=${{ matrix.python-version }} + conda activate mpas_analysis_dev + python -m pip install --no-deps --no-build-isolation -vv -e . + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Run Tests + env: + CHECK_IMAGES: False + run: | + set -e + conda activate mpas_analysis_dev + pip check + pytest --pyargs mpas_analysis + mpas_analysis --help + download_analysis_data --help + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Build Sphinx Docs + run: | + conda activate mpas_analysis_dev + # sphinx-multiversion expects at least a "main" branch + git branch main || echo "branch main already exists." + cd docs + sphinx-multiversion . _build/html + From 9edc4872d021da3c2aee6dc1b5ef92ffe32928c1 Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Thu, 10 Oct 2024 16:07:32 -0700 Subject: [PATCH 3/5] Add `sphinx-multiversion` package --- dev-spec.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev-spec.txt b/dev-spec.txt index 0b40a6e50..c24ed3e30 100644 --- a/dev-spec.txt +++ b/dev-spec.txt @@ -44,4 +44,5 @@ m2r2>=0.3.3 mistune<2 sphinx sphinx_rtd_theme +sphinx-multiversion tabulate From ab41913d331901bab18dd5a88f4ba08ee69bb4ee Mon Sep 17 00:00:00 2001 From: Althea Denlinger Date: Tue, 15 Oct 2024 09:37:01 -0700 Subject: [PATCH 4/5] Add docs workflow --- .github/workflows/docs_workflow.yml | 95 +++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/docs_workflow.yml diff --git a/.github/workflows/docs_workflow.yml b/.github/workflows/docs_workflow.yml new file mode 100644 index 000000000..750c25d85 --- /dev/null +++ b/.github/workflows/docs_workflow.yml @@ -0,0 +1,95 @@ +name: CI/CD Release Workflow + +on: + push: + branches: + - main + - develop + + release: + types: [published] + +jobs: + publish-docs: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Cache Conda + uses: actions/cache@v4 + env: + # Increase this value to reset cache if deploy/conda-dev-spec.template has not changed in the workflow + CACHE_NUMBER: 0 + with: + path: ~/conda_pkgs_dir + key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ + hashFiles('dev-spec.txt') }} + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Set up Conda Environment + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: "mpas_analysis_ci" + miniforge-version: latest + channels: conda-forge + channel-priority: strict + auto-update-conda: true + python-version: ${{ matrix.python-version }} + + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + name: Install mpas_analysis + run: | + git config --global url."https://github.com/".insteadOf "git@github.com:" + conda create -n mpas_analysis_dev --file dev-spec.txt \ + python=${{ matrix.python-version }} + conda activate mpas_analysis_dev + python -m pip install -vv --no-deps --no-build-isolation -e . + + - name: Build Sphinx Docs + run: | + set -e + conda activate mpas_analysis_dev + pip check + mpas_analysis sync diags --help + cd docs + sphinx-multiversion . _build/html + - name: Copy Docs and Commit + run: | + set -e + conda activate mpas_analysis_dev + pip check + mpas_analysis sync diags --help + cd docs + # gh-pages branch must already exist + git clone https://github.com/MPAS-Dev/MPAS-Analysis.git --branch gh-pages --single-branch gh-pages + # Make sure we're in the gh-pages directory. + cd gh-pages + # Create `.nojekyll` (if it doesn't already exist) for proper GH Pages configuration. + touch .nojekyll + # Add `index.html` to point to the `develop` branch automatically. + printf '' > index.html + # Only replace `${{ github.head_ref || github.ref_name }}` docs with latest changes. Docs for releases should be untouched. + rm -rf ${{ github.head_ref || github.ref_name }} + # don't clobber existing release versions (in case we retroactively fixed them) + cp -r -n ../_build/html/* . + # Configure git using GitHub Actions credentials. + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + # The second command will fail if no changes were present, so we ignore it + git add . + git commit -m "Update documentation" -a || true + - name: Push Changes + uses: ad-m/github-push-action@master + with: + branch: gh-pages + directory: docs/gh-pages + github_token: ${{ secrets.GITHUB_TOKEN }} + force: true + From 06437ad91b32efcdfcc9a221de7ee7417453cbee Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 19 Oct 2024 00:59:32 +0200 Subject: [PATCH 5/5] Clarify comment --- .github/workflows/docs_workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs_workflow.yml b/.github/workflows/docs_workflow.yml index 750c25d85..d11d3f4b1 100644 --- a/.github/workflows/docs_workflow.yml +++ b/.github/workflows/docs_workflow.yml @@ -75,7 +75,8 @@ jobs: touch .nojekyll # Add `index.html` to point to the `develop` branch automatically. printf '' > index.html - # Only replace `${{ github.head_ref || github.ref_name }}` docs with latest changes. Docs for releases should be untouched. + # Only replace docs in a directory with the destination branch name with latest changes. Docs for + # releases should be untouched. rm -rf ${{ github.head_ref || github.ref_name }} # don't clobber existing release versions (in case we retroactively fixed them) cp -r -n ../_build/html/* .