diff --git a/.github/workflows/builds-review.yaml b/.github/workflows/builds-review.yaml new file mode 100644 index 0000000..003fb05 --- /dev/null +++ b/.github/workflows/builds-review.yaml @@ -0,0 +1,60 @@ +name: Review builds + +on: + # NOTE: github.event context is pull_request payload: + # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request + pull_request: + types: + - labeled + +jobs: + build: + if: >- + !github.event.repository.fork + && github.event.label.name == 'build::review' + strategy: + matrix: + include: + - runner: ubuntu-latest + subdir: noarch + runs-on: ${{ matrix.runner }} + steps: + - name: Remove build label + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.CANARY_ACTION_TOKEN }} + script: | + const { data: pullRequest } = await github.rest.pulls.get({ + ...context.repo, + pull_number: context.issue.number, + }) + const buildLabel = '${{ github.event.label.name }}' + const labels = pullRequest.labels.map(label => label.name) + const hasBuildLabel = labels.includes(buildLabel) + + if (hasBuildLabel) { + await github.rest.issues.removeLabel({ + ...context.repo, + issue_number: context.issue.number, + name: buildLabel, + }) + } + + # Clean checkout of specific git ref needed for package metadata version + # which needs env vars GIT_DESCRIBE_TAG and GIT_BUILD_STR: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + clean: true + fetch-depth: 0 + + - name: Create and upload review build + uses: conda/actions/canary-release@v23.7.0 + with: + package-name: ${{ github.event.repository.name }} + subdir: ${{ matrix.subdir }} + anaconda-org-channel: conda-canary + anaconda-org-label: ${{ github.repository_owner }}-${{ github.event.repository.name }}-pr-${{ github.event.number }} + anaconda-org-token: ${{ secrets.ANACONDA_ORG_CONDA_CANARY_TOKEN }} + comment-headline: Review build status + comment-token: ${{ secrets.CANARY_ACTION_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b04746c..51e7106 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,16 +1,19 @@ name: Tests on: - # NOTE: github.event context is push payload: - # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push + # https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#push push: branches: - main + - feature/** + - '[0-9].*.x' # e.g., 1.3.x - # NOTE: github.event context is pull_request payload: - # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request + # https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request pull_request: + # https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch + workflow_dispatch: + concurrency: # Concurrency group that uses the workflow name and PR number if available # or commit SHA as a fallback. If a new build is triggered under that @@ -69,3 +72,72 @@ jobs: uses: codecov/codecov-action@v3 with: flags: ${{ matrix.python-version }},${{ runner.os }} + + # canary builds + build: + name: Canary Build + needs: [tests] + # only build canary build if + # - prior steps succeeded, + # - this is the main repo, and + # - we are on the main, feature, or release branch + if: >- + always() + && !github.event.repository.fork + && ( + github.ref_name == 'main' + || startsWith(github.ref_name, 'feature/') + || endsWith(github.ref_name, '.x') + ) + strategy: + matrix: + include: + - runner: ubuntu-latest + subdir: noarch + runs-on: ${{ matrix.runner }} + steps: + # Clean checkout of specific git ref needed for package metadata version + # which needs env vars GIT_DESCRIBE_TAG and GIT_BUILD_STR: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + clean: true + fetch-depth: 0 + + # Explicitly use Python 3.11 since each of the OSes has a different default Python + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Detect label + shell: python + run: | + from pathlib import Path + from re import match + from os import environ + + if "${{ github.ref_name }}" == "main": + # main branch commits are uploaded to the dev label + label = "dev" + elif "${{ github.ref_name }}".startswith("feature/"): + # feature branch commits are uploaded to a custom label + label = "${{ github.ref_name }}" + else: + # release branch commits are added to the rc label + # see https://github.com/conda/infrastructure/issues/760 + _, name = "${{ github.repository }}".split("/") + label = f"rc-{name}-${{ github.ref_name }}" + + Path(environ["GITHUB_ENV"]).write_text(f"ANACONDA_ORG_LABEL={label}") + + - name: Create and upload canary build + uses: conda/actions/canary-release@v23.7.0 + env: + # Run conda-build in isolated activation to properly package conda + _CONDA_BUILD_ISOLATED_ACTIVATION: 1 + with: + package-name: ${{ github.event.repository.name }} + subdir: ${{ matrix.subdir }} + anaconda-org-channel: conda-canary + anaconda-org-label: ${{ env.ANACONDA_ORG_LABEL }} + anaconda-org-token: ${{ secrets.ANACONDA_ORG_CONDA_CANARY_TOKEN }} diff --git a/news/68-canary b/news/68-canary new file mode 100644 index 0000000..e672795 --- /dev/null +++ b/news/68-canary @@ -0,0 +1,19 @@ +### Enhancements + +* Add canary builds. (#68) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +*