Merge branch 'main' into develop #63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI ModMet | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main, develop] | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 | |
| with: | |
| path: ~/conda_pkgs_dir | |
| key: ${{ runner.os }}-conda-${{ hashFiles('modmet.yml') }} | |
| - uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4 | |
| with: | |
| environment-file: modmet.yml | |
| activate-environment: modmet | |
| auto-activate: false | |
| use-only-tar-bz2: false | |
| - name: Install fortitude-lint==0.9.0 | |
| run: pip install fortitude-lint | |
| - name: Run Fortitude style checker | |
| run: fortitude check | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 | |
| with: | |
| path: ~/conda_pkgs_dir | |
| key: ${{ runner.os }}-conda-${{ hashFiles('modmet.yml') }} | |
| - uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4 | |
| with: | |
| environment-file: modmet.yml | |
| activate-environment: modmet | |
| auto-activate: false | |
| use-only-tar-bz2: false | |
| - name: Build with fpm | |
| shell: bash -el {0} | |
| run: | | |
| fpm --version | |
| fpm build | |
| test: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 | |
| with: | |
| path: ~/conda_pkgs_dir | |
| key: ${{ runner.os }}-conda-${{ hashFiles('modmet.yml') }} | |
| - uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4 | |
| with: | |
| environment-file: modmet.yml | |
| activate-environment: modmet | |
| auto-activate: false | |
| use-only-tar-bz2: false | |
| - name: Run tests | |
| shell: bash -el {0} | |
| run: fpm test | |
| coverage: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6 | |
| with: | |
| path: ~/conda_pkgs_dir | |
| key: ${{ runner.os }}-conda-${{ hashFiles('modmet.yml') }} | |
| - uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4 | |
| with: | |
| environment-file: modmet.yml | |
| activate-environment: modmet | |
| auto-activate: false | |
| use-only-tar-bz2: false | |
| - name: Generate coverage report | |
| shell: bash -el {0} | |
| run: ./scripts/gen_coverage.sh | |
| - name: Store coverage artifacts | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| with: | |
| name: coverage-html | |
| path: coverage_html/ | |
| version_release: | |
| needs: [lint, build, test, coverage] | |
| if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Guard against re-bumping | |
| id: guard | |
| run: | | |
| if git diff --name-only "${{ github.event.before }}" "${{ github.sha }}" | grep -qx "VERSION"; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "VERSION changed in this push; skipping bump job" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Download coverage artifacts | |
| if: steps.guard.outputs.skip != 'true' | |
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 | |
| with: | |
| name: coverage-html | |
| path: coverage_html/ | |
| - name: Configure Git identity | |
| if: steps.guard.outputs.skip != 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Bump version files | |
| if: steps.guard.outputs.skip != 'true' | |
| run: ./scripts/bump_version.sh | |
| - name: Update coverage badge in README | |
| if: steps.guard.outputs.skip != 'true' | |
| run: COVERAGE_ENV_FILE=coverage.env ./scripts/update_coverage_badge.sh | |
| - name: Read bump metadata | |
| if: steps.guard.outputs.skip != 'true' | |
| run: | | |
| source version.env | |
| source coverage.env | |
| echo "old_version=${OLD_VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "release_date=${RELEASE_DATE}" >> "$GITHUB_OUTPUT" | |
| echo "coverage_percent=${COVERAGE_PERCENT}" >> "$GITHUB_OUTPUT" | |
| echo "coverage_color=${COVERAGE_COLOR}" >> "$GITHUB_OUTPUT" | |
| id: bump | |
| - name: Commit and push bump branch | |
| if: steps.guard.outputs.skip != 'true' | |
| run: | | |
| source version.env | |
| BRANCH="ci/version-bump-${NEW_VERSION}" | |
| git add VERSION README.md src/modmet_version.f90 | |
| if git diff --cached --quiet; then | |
| echo "No bump changes detected; skipping branch push" | |
| exit 0 | |
| fi | |
| git commit -m "chore: bump version to ${NEW_VERSION}" | |
| git push --force-with-lease origin HEAD:"${BRANCH}" | |
| echo "BUMP_BRANCH=${BRANCH}" >> "$GITHUB_ENV" | |
| - name: Open or update bump PR | |
| env: | |
| GH_API_TOKEN: ${{ github.token }} | |
| if: steps.guard.outputs.skip != 'true' | |
| run: | | |
| source version.env | |
| BRANCH="ci/version-bump-${NEW_VERSION}" | |
| API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}" | |
| if [[ -z "${GH_API_TOKEN:-}" ]]; then | |
| echo "Missing github.token in workflow environment" >&2 | |
| exit 1 | |
| fi | |
| EXISTING_PR=$(curl -fsSL \ | |
| -H "Authorization: Bearer ${GH_API_TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "${API_URL}/pulls?state=open&head=${GITHUB_REPOSITORY_OWNER}:${BRANCH}&base=develop" | jq -r '.[0].number // empty') | |
| if [[ -n "${EXISTING_PR}" ]]; then | |
| echo "Bump PR already open: #${EXISTING_PR}" | |
| exit 0 | |
| fi | |
| curl -fsSL -X POST \ | |
| -H "Authorization: Bearer ${GH_API_TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "${API_URL}/pulls" \ | |
| -d @- <<EOF | |
| { | |
| "title": "chore: bump version to ${NEW_VERSION}", | |
| "head": "${BRANCH}", | |
| "base": "develop", | |
| "body": "Automated version bump generated by CI.\\n\\n- Version: ${NEW_VERSION}\\n- Release date: ${{ steps.bump.outputs.release_date }}\\n- Coverage: ${{ steps.bump.outputs.coverage_percent }}% (${{ steps.bump.outputs.coverage_color }})" | |
| } | |
| EOF | |
| release_from_bump_commit: | |
| needs: [lint, build, test, coverage] | |
| if: "${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve version | |
| id: rel | |
| run: | | |
| VERSION="$(tr -d '[:space:]' < VERSION)" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| - name: Decide whether to release | |
| id: release_guard | |
| run: | | |
| VERSION_CHANGED="false" | |
| if git diff --name-only "${{ github.event.before }}" "${{ github.sha }}" | grep -qx "VERSION"; then | |
| VERSION_CHANGED="true" | |
| fi | |
| TAG_EXISTS="false" | |
| VERSION="${{ steps.rel.outputs.version }}" | |
| if git ls-remote --exit-code --tags origin "refs/tags/${VERSION}" >/dev/null 2>&1; then | |
| TAG_EXISTS="true" | |
| fi | |
| if [[ "${VERSION_CHANGED}" == "true" && "${TAG_EXISTS}" == "false" ]]; then | |
| echo "should_release=true" >> "$GITHUB_OUTPUT" | |
| echo "Proceeding: VERSION changed and tag ${VERSION} does not exist" | |
| else | |
| echo "should_release=false" >> "$GITHUB_OUTPUT" | |
| echo "Skipping release: VERSION_CHANGED=${VERSION_CHANGED}, TAG_EXISTS=${TAG_EXISTS}" | |
| fi | |
| - name: Create and push tag | |
| if: steps.release_guard.outputs.should_release == 'true' | |
| run: | | |
| VERSION="${{ steps.rel.outputs.version }}" | |
| git tag "${VERSION}" | |
| git push origin "${VERSION}" | |
| - name: Create GitHub release | |
| if: steps.release_guard.outputs.should_release == 'true' | |
| uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 | |
| with: | |
| tag_name: ${{ steps.rel.outputs.version }} | |
| name: ModMet ${{ steps.rel.outputs.version }} | |
| body: | | |
| Automated release for ModMet version ${{ steps.rel.outputs.version }}. |