From c9158b914f7379ae44bb9e9ee817943451192d31 Mon Sep 17 00:00:00 2001 From: Philip Loche Date: Wed, 18 Dec 2024 14:32:25 +0100 Subject: [PATCH] use comment artifact action --- .github/workflows/build-wheels.yml | 7 ++ .github/workflows/comment-download.yml | 100 ---------------------- .github/workflows/docs.yml | 7 ++ .github/workflows/documentation-links.yml | 17 ---- .readthedocs.yml | 37 -------- 5 files changed, 14 insertions(+), 154 deletions(-) delete mode 100644 .github/workflows/comment-download.yml delete mode 100644 .github/workflows/documentation-links.yml delete mode 100644 .readthedocs.yml diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index f1066591c..7df86875b 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -330,6 +330,7 @@ jobs: runs-on: ubuntu-22.04 permissions: contents: write + pull-requests: write steps: - name: Download featomic wheels uses: actions/download-artifact@v4 @@ -359,6 +360,12 @@ jobs: wheels/* wheels/cxx/* + - name: Comment with download link + uses: PicoCentauri/comment-artifact@v1 + with: + name: wheels + description: ⚙️ [Download Python wheels for this pull-request (you can install these with pip) + - name: upload to GitHub release (featomic) if: startsWith(github.ref, 'refs/tags/featomic-v') uses: softprops/action-gh-release@v2 diff --git a/.github/workflows/comment-download.yml b/.github/workflows/comment-download.yml deleted file mode 100644 index d380c847f..000000000 --- a/.github/workflows/comment-download.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: Comment on pull request -on: - workflow_run: - workflows: ['Build Python wheels'] - types: [completed] - -permissions: - pull-requests: write - -jobs: - pr_comment: - if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' - runs-on: ubuntu-latest - steps: - - uses: actions/github-script@v7 - with: - script: | - async function getArtifactLink(artifactName, owner, repo, run_id) { - // get the list of artifacts - const artifacts = await github.paginate( - github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id} - ); - - if (!artifacts.length) { - return core.error(`No artifacts found`); - } - - for (const artifact of artifacts) { - if (artifact.name == artifactName) { - return `https://nightly.link/${owner}/${repo}/actions/artifacts/${artifact.id}.zip`; - } - } - return core.error(`failed to find ${artifactName} artifact`); - } - let link; - let body_message; - - const {owner, repo} = context.repo; - const run_id = ${{github.event.workflow_run.id}}; - const workflow_name = "${{github.event.workflow_run.name}}"; - - console.info(`${workflow_name} triggered this run`) - - // Find the PR with the right sha, see https://github.com/orgs/community/discussions/25220 - const response = await github.rest.search.issuesAndPullRequests({ - q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', - per_page: 1, - }) - - const items = response.data.items - if (items.length < 1) { - return core.error("No matching pull requests found"); - } - - const pull_number = items[0].number; - console.info("Pull request number is", pull_number) - - if (workflow_name == 'Documentation') { // currently unused, this is done by readthedocs - link = await getArtifactLink('docs', owner, repo, run_id); - // Add horizontal line for docs only because assuming this is one - // triggered first. The wheels building should take much longer... - body_message = `\n----\n 📚 [Download documentation preview for this pull-request](${link})\n`; - } else { // wheels - link = await getArtifactLink('wheels', owner, repo, run_id); - body_message = `⚙️ [Download Python wheels for this pull-request (you can install these with pip)](${link})\n`; - } - - const MESSAGE_SEPARATOR_START = `\r\n\r\n\r\n`; - const MESSAGE_SEPARATOR_END = `\r\n`; - - const { data: pull } = await github.rest.pulls.get({ - owner: owner, - repo: repo, - pull_number: pull_number, - }); - - let body = ""; - if (pull.body) { - if (pull.body.indexOf(MESSAGE_SEPARATOR_START) === -1) { - // First time updating this description - body = pull.body + MESSAGE_SEPARATOR_START + body_message + MESSAGE_SEPARATOR_END; - } - else { - // we already updated this description before - body = pull.body.slice(0, pull.body.indexOf(MESSAGE_SEPARATOR_START)); - body = body + MESSAGE_SEPARATOR_START + body_message + MESSAGE_SEPARATOR_END; - body = body + pull.body.slice(pull.body.indexOf(MESSAGE_SEPARATOR_END) + MESSAGE_SEPARATOR_END.length); - } - } - else { - // Pull Request description is empty - body = MESSAGE_SEPARATOR_START + body_message + MESSAGE_SEPARATOR_END; - } - - github.rest.pulls.update({ - owner: owner, - repo: repo, - pull_number: pull_number, - body: body, - }); diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 9a8889ed7..7e732a7a1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,6 +16,7 @@ jobs: runs-on: ubuntu-22.04 permissions: contents: write + pull-requests: write steps: - name: free disk space run: sudo rm -rf /usr/share/dotnet /usr/local/lib/android || true @@ -50,6 +51,12 @@ jobs: path: docs/build/html/* overwrite: true # only keep the latest version of the documentation + - name: Comment with download link + uses: PicoCentauri/comment-artifact@v1 + with: + name: docs + description: 📚 Download documentation for this pull-request + - name: put documentation in the website run: | git clone https://github.com/$GITHUB_REPOSITORY --branch gh-pages gh-pages diff --git a/.github/workflows/documentation-links.yml b/.github/workflows/documentation-links.yml deleted file mode 100644 index 9497eed36..000000000 --- a/.github/workflows/documentation-links.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: readthedocs/actions - -on: - pull_request_target: - types: - - opened - -permissions: - pull-requests: write - -jobs: - documentation-links: - runs-on: ubuntu-latest - steps: - - uses: readthedocs/actions/preview@v1 - with: - project-slug: featomic diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 70efee587..000000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,37 +0,0 @@ -# .readthedocs.yml -# Read the Docs configuration file -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details - -# Required -version: 2 - -# Set the version of Python and other tools we need -build: - os: ubuntu-22.04 - apt_packages: - - cmake - tools: - python: "3.12" - rust: "1.75" - jobs: - post_install: - # install featomic-torch with the CPU version of PyTorch. We can not use - # the `python` section below since it does not allow to specify - # `--extra-index-url` - - pip install --extra-index-url https://download.pytorch.org/whl/cpu python/featomic_torch - pre_build: - # Pre-build Rust code here to avoid timeout when building docs - - cargo build - - cargo build --release - - cargo doc -p featomic - -# Build documentation in the docs/ directory with Sphinx -sphinx: - configuration: docs/src/conf.py - -# Declare the Python requirements required to build the docs -python: - install: - - method: pip - path: . - - requirements: docs/requirements.txt