diff --git a/.github/actions/sphinx/deploy/action.yml b/.github/actions/sphinx/deploy/action.yml index e6118ee0f3..d3568bc666 100644 --- a/.github/actions/sphinx/deploy/action.yml +++ b/.github/actions/sphinx/deploy/action.yml @@ -14,8 +14,7 @@ inputs: required: false default: scaleway BUCKET: - required: false - default: prod-probabl-skore + required: true SOURCE: required: true DESTINATION: diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 0b81b67a3a..bceacb9b9f 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -90,7 +90,7 @@ jobs: python -m pytest -n auto --junitxml=coverage/coverage.xml --cov=skore src/ tests/ | tee coverage/coverage.txt - name: Upload coverage reports - if: ${{ matrix.coverage }} + if: ${{ matrix.coverage && (github.event_name == 'pull_request') }} uses: actions/upload-artifact@v4 with: name: backend-coverage diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index 5e6220b552..641493bae6 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -63,6 +63,7 @@ jobs: npm run test:unit:coverage - name: Upload coverage reports + if: ${{ github.event_name == 'pull_request' }} uses: actions/upload-artifact@v4 with: name: frontend-coverage diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml new file mode 100644 index 0000000000..ff83a624d4 --- /dev/null +++ b/.github/workflows/pr-cleanup.yml @@ -0,0 +1,79 @@ +name: cleanup PR + +on: + pull_request_target: + types: [closed] + +permissions: {} + +defaults: + run: + shell: "bash" + +jobs: + clean-artifacts: + if: always() + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Clean artifacts + run: | + set -u + + ARTIFACTS=$( \ + gh api \ + --paginate \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/probabl-ai/skore/actions/artifacts \ + | \ + jq -c " \ + .artifacts[] \ + | select((.workflow_run.head_branch == \"${HEAD_BRANCH}\") and (.workflow_run.head_repository_id == ${HEAD_REPOSITORY_ID})) \ + | {id: .id, name: .name} \ + " \ + ) + + for ARTIFACT in $ARTIFACTS; do + ID=$(echo "${ARTIFACT}" | jq -r '.id') + NAME=$(echo "${ARTIFACT}" | jq -r '.name') + + echo "Deleting artifact (NAME: \"${NAME}\", ID: \"${ID}\")" + + gh api \ + --method DELETE \ + --silent \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/${REPOSITORY_OWNER}/${REPOSITORY_NAME}/actions/artifacts/${ID} + done + env: + GH_TOKEN: ${{ github.token }} + REPOSITORY_OWNER: ${{ github.repository_owner }} + REPOSITORY_NAME: ${{ github.event.repository.name }} + HEAD_REPOSITORY_ID: ${{ github.event.pull_request.head.repo.id }} + HEAD_BRANCH: ${{ github.head_ref }} + + clean-documentation-preview: + if: always() + runs-on: ubuntu-latest + steps: + - name: Install `rclone` + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y rclone + + - name: Copy configuration + shell: bash + run: echo "${CONFIGURATION}" > rclone.configuration + env: + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }} + + - name: Clean documentation preview + run: rclone --config rclone.configuration purge "${PROVIDER}:${BUCKET}/${PULL_REQUEST_NUMBER}" + env: + PROVIDER: scaleway + BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }} + PULL_REQUEST_NUMBER: ${{ github.event.number }} diff --git a/.github/workflows/pr-serve-documentation-preview.yml b/.github/workflows/pr-serve-documentation-preview.yml new file mode 100644 index 0000000000..4362d3ec10 --- /dev/null +++ b/.github/workflows/pr-serve-documentation-preview.yml @@ -0,0 +1,71 @@ +name: serve documentation preview in PR + +on: + workflow_run: + workflows: [sphinx] + types: [completed] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: {} + +jobs: + acquire-pr-context: + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + outputs: + PR_NUMBER: ${{ steps.acquire-pr-context.outputs.number }} + PR_HEADSHA: ${{ steps.acquire-pr-context.outputs.headsha }} + permissions: + contents: read + steps: + - id: acquire-pr-context + run: gh pr view --repo "${REPOSITORY}" "${BRANCH}" --json 'number,headRefOid' --jq '"number=\(.number)\nheadsha=\(.headRefOid)"' >> "${GITHUB_OUTPUT}" + env: + GH_TOKEN: ${{ github.token }} + REPOSITORY: ${{ github.repository }} + BRANCH: |- + ${{ + (github.event.workflow_run.head_repository.fork == true) + && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) + || github.event.workflow_run.head_branch + }} + + serve-documentation-preview: + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + needs: [acquire-pr-context] + permissions: + actions: read + contents: read + pull-requests: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download HTML artifacts + uses: actions/download-artifact@v4 + with: + name: sphinx-html-artifact + path: html/ + github-token: ${{ github.token }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Serve documentation preview + uses: ./.github/actions/sphinx/deploy + with: + CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }} + BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }} + SOURCE: html/ + DESTINATION: ${{ needs.acquire-pr-context.outputs.PR_NUMBER }}/ + + - name: Comment with documentation preview link + uses: marocchino/sticky-pull-request-comment@v2 + with: + number: ${{ needs.acquire-pr-context.outputs.PR_NUMBER }} + header: documentation-preview + message: >- + [Documentation preview](${{ vars.DOCUMENTATION_PREVIEW_URL }}/${{ needs.acquire-pr-context.outputs.PR_NUMBER }}) + @ ${{ needs.acquire-pr-context.outputs.PR_HEADSHA }} diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml index cfdd2eb617..a91976798a 100644 --- a/.github/workflows/sphinx.yml +++ b/.github/workflows/sphinx.yml @@ -116,8 +116,8 @@ jobs: path: sphinx/build/html/ sphinx-deploy-html: - runs-on: ubuntu-latest if: ${{ (github.event_name == 'release') || (github.event_name == 'push' && github.ref == 'refs/heads/main') }} + runs-on: ubuntu-latest needs: [sphinx-version, sphinx-build] steps: - uses: actions/checkout@v4 @@ -128,12 +128,13 @@ jobs: - uses: ./.github/actions/sphinx/deploy with: CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }} + BUCKET: ${{ vars.DOCUMENTATION_BUCKET }} SOURCE: html/ DESTINATION: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }}/ sphinx-deploy-root-files: - runs-on: ubuntu-latest if: ${{ github.event_name == 'release' }} + runs-on: ubuntu-latest needs: [sphinx-version, sphinx-build, sphinx-deploy-html] steps: - uses: actions/checkout@v4 @@ -144,7 +145,7 @@ jobs: import operator import json - url = "https://skore.probabl.ai" + url = os.environ["URL"] current = os.environ["CURRENT"] response = requests.get(f"{url}/versions.json") @@ -177,17 +178,19 @@ jobs: """ ) env: + URL: ${{ vars.DOCUMENTATION_URL }} CURRENT: ${{ needs.sphinx-version.outputs.SPHINX_VERSION }} - uses: ./.github/actions/sphinx/deploy with: CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOCS }} + BUCKET: ${{ vars.DOCUMENTATION_BUCKET }} ACTION: copy SOURCE: artifacts/ DESTINATION: - sphinx-clean: + sphinx-clean-artifacts: runs-on: ubuntu-latest - if: always() + if: ${{ always() && (github.event_name != 'pull_request') }} needs: [sphinx-version, sphinx-build, sphinx-deploy-html, sphinx-deploy-root-files] steps: - uses: geekyeggo/delete-artifact@v5