pontifex 1.1.2

An abstraction for building and interacting with AWS Nitro enclaves.
Documentation
name: Release

on:
  pull_request:
    types: [closed]
    branches:
      - main

jobs:
  pre-release-checks:
    if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.user.login == 'github-actions[bot]'
    runs-on: ubuntu-latest
    permissions:
      contents: write
    outputs:
      new_version: ${{ steps.version.outputs.new_version }}
      commit_sha: ${{ github.sha }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Get new version
        id: version
        run: |
          NEW_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.workspace_members[0]' | cut -d '#' -f2)
          echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT

      - name: Check latest published version
        id: latest_version
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: |
          LATEST_RELEASE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
            "https://api.github.com/repos/${{ github.repository }}/releases/latest" | \
            jq -r .tag_name | sed 's/^v//')

          echo "Latest release: $LATEST_RELEASE"

          NEW_VERSION="${{ steps.version.outputs.new_version }}"

          echo "New version: $NEW_VERSION"

          # Ensure the new version is greater than the latest published version
          if ! { [ "$(printf '%s\n' "$LATEST_RELEASE" "$NEW_VERSION" | sort -V | tail -n1)" = "$NEW_VERSION" ] && \
                 [ "$NEW_VERSION" != "$LATEST_RELEASE" ]; }; then
            echo "Error: New version ($NEW_VERSION) is not greater than latest release ($LATEST_RELEASE)"
            exit 1
          fi
      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          name: ${{ steps.version.outputs.new_version }}
          tag_name: ${{ steps.version.outputs.new_version }}
          generate_release_notes: true
          make_latest: true

  publish-to-crates-io:
    needs: [pre-release-checks]
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          ref: ${{ needs.pre-release-checks.outputs.commit_sha }} # to ensure builds are consistent

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          cargo publish --token $CARGO_REGISTRY_TOKEN --package pontifex --locked