---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/public-workflows.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/concepts/public-workflows.md
  - href: https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/public-workflows.md
    type: text/markdown
    title: Markdown version
  - href: https://sourcecraft.dev/portal/docs/en/llms.txt
    type: text/markdown
    title: llms.txt
title: Public workflows in SourceCraft
description: How to make CI/CD workflows publicly available for running to all organization members in SourceCraft.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Public workflows in SourceCraft

<!-- source: en/_includes/sourcecraft/ci-cd/public-workflow-intro.md -->
You can make SourceCraft [workflows](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#workflows) runnable by all [organization](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/index.md#org) members. You can grant access to them even if there are no [roles](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/index.md#roles-list) in the repository the workflow resides in and no access to its [secrets](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/index.md#secrets).

The member who runs such a public workflow is able to feed into it the [inputs](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/workflows.md#inputs), follow its progress, and get the output data, including artifacts.

You can use this feature, for example, to check tasks in students' test repositories. Another potential use is granting access to some of the CI processes without assigning additional roles to users.

<iframe width="640" height="360" src="https://runtime.strm.yandex.ru/player/video/vplvp7vkj6yzv4bcgv6o?autoplay=0&mute=0" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" frameborder="0" scrolling="no"></iframe>
<!-- endsource: en/_includes/sourcecraft/ci-cd/public-workflow-intro.md -->

## Public workflow configuration {#configuration}

A workflow becomes public if you provide `settings: shared: true` in the default branch of its configuration file, `.sourcecraft/ci.yaml`. Here is an example:

<!-- source: en/_includes/sourcecraft/ci-cd/public-workflow-config-example.md -->
```yaml
workflows:
  professor-test:
    inputs:
      STUDENTREPO:
        type: string
        required: true
      TASK:
        type: string
        required: true
    settings:
      shared: true
    tasks:
      - name: professor-task
        cubes:
          - name: professor-cube
            script:
              - |
              	mkdir -p artifacts
                echo "Repo: ${{ inputs.STUDENTREPO }}" > artifacts/professor-output
                echo "Task: ${{ inputs.TASK }}" >> artifacts/professor-output
            artifacts:
              paths:
                - artifacts/professor-output

on:
  push: professor-test
```
<!-- endsource: en/_includes/sourcecraft/ci-cd/public-workflow-config-example.md -->

<!-- source: en/_includes/sourcecraft/ci-cd/public-workflow-user-warning.md -->
{% note warning %}

All public workflow runs are performed by the user who adds the last update to `.sourcecraft/ci.yaml` in the main branch.

If `.sourcecraft/ci.yaml` in the main branch was updated directly via `git push origin main` using a limited-lifetime [personal access token (PAT)](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/pat.md), the workflow will remain public only during that lifetime.

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/ci-cd/public-workflow-user-warning.md -->

<!-- source: en/_includes/sourcecraft/configuration-tip.md -->
{% note tip %}

You can set up and view repository configurations in the SourceCraft interface under ![image](../../_assets/console-icons/gear.svg) **Repository settings** in the ![image](../../_assets/console-icons/nut-hex.svg) **Configurations** section. Learn more in [this article](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configuration-edit.md).

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/configuration-tip.md -->

## Public workflow execution {#run}

<!-- source: en/_includes/sourcecraft/ci-cd/public-workflow-run-intro.md -->
You can start a public workflow from within another workflow using the special `cr.yandex/sourcecraft/cubes/shared-workflows:latest` [cube](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#cubes) or via the API. 

In the input parameters, provide the following:
* Slug of the repository containing the workflow.
* Organization slug.
* Workflow name.
* Optionally, the [inputs](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/workflows.md#inputs) parameters, e.g., the link for cloning the repository you are starting the workflow from.
* Optionally, a reference to the execution result: [artifacts](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/cubes.md).

  {% note warning %}

  To get the artifacts from a public workflow, provide the job and cube names and the local artifact path to the environment variables of the `cr.yandex/sourcecraft/cubes/shared-workflows:latest` cube or in a separate API call.

  {% endnote %}
<!-- endsource: en/_includes/sourcecraft/ci-cd/public-workflow-run-intro.md -->

Here are some examples:

{% list tabs group=instructions %}

- CI/CD {#ci-cd}

  <!-- source: en/_includes/sourcecraft/ci-cd/public-workflow-run-example-ci.md -->
  ```yaml
  workflows:
    check-solution:
      tasks:
        - name: main
          cubes:
            - name: run-shared-workflow
              image: cr.yandex/sourcecraft/cubes/shared-workflows:latest
              env:
                ORG_SLUG: professor-org
                REPO_SLUG: professor-repo
                WORKFLOW_NAME: professor-test
                WORKFLOW_VALUES: '[{"name": "STUDENTREPO", "value": "student"}, {"name": "TASK", "value": "task-1"}]'
                TASK_NAME: professor-task
                CUBE_NAME: professor-cube
                ARTIFACT_LOCAL_PATH: artifacts/professor-output
              artifacts:
                paths:
                  - artifacts/output

  on:
    push: check-solution
  ```
  <!-- endsource: en/_includes/sourcecraft/ci-cd/public-workflow-run-example-ci.md -->

  <!-- source: en/_includes/sourcecraft/ci-cd/unpack-artifact-note.md -->
  {% note info %}

  To unpack an artifact that is a folder or a tar archive, specify the `UNPACK_ARTIFACT: true` environment variable. This will unpack the downloaded artifact `artifacts/output` into the `artifacts` folder using the `tar -xf artifacts/output -C artifacts` command.

  {% endnote %}
  <!-- endsource: en/_includes/sourcecraft/ci-cd/unpack-artifact-note.md -->

- API {#api}

  <!-- source: en/_includes/sourcecraft/ci-cd/public-workflow-run-example-api.md -->
  1. [Create](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/pat.md#create) a personal access token (PAT).
  1. Run the public workflow by providing `"shared": true` in the request body:

      ```bash
      export PAT=<personal_access_token>

      cat > body.json << 'EOF'
      {
        "workflows": [
          {
            "name": "professor-test",
            "values": [
              {
                "name": "STUDENTREPO",
                "value": "student"
              },
              {
                "name": "TASK",
                "value": "task-1"
              }
            ]
          }
        ],
        "shared": true
      }
      EOF

      curl \
        --request POST \
        --header "Authorization: Bearer $PAT" \
        --data '@body.json' \
        --url "https://api.sourcecraft.tech/<organization_slug>/<repository_slug>/cicd/runs"
      ```

      {% note warning %}

      You can only run a public workflow in the repository's main branch and only with the CI/CD configuration from the main branch. Providing `head` and `config_revision` in the request body will produce an execution error.

      {% endnote %}

      Save the execution `slug` value from the response.

  1. Get the status of a running workflow:

      ```bash
      curl \
        --request GET \
        --header "Authorization: Bearer $PAT" \
        --url "https://api.sourcecraft.tech/<organization_slug>/<repository_slug>/cicd/runs/<execution_slug>"
      ```

      {% note info %}

      The status and artifacts of a public workflow can only be accessed with the same [personal token (PAT)](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/pat.md) used to run the workflow.

      {% endnote %}

  1. Get artifacts of a running workflow:

      ```bash
      curl \
        --request GET \
        --header "Authorization: Bearer $PAT" \
        --url "https://api.sourcecraft.tech/<organization_slug>/<repository_slug>/cicd/artifacts/<execution_slug>/professor-test/professor-task/professor-cube"
      ```

  For more information, see [Working with the SourceCraft REST API](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/api-start.md).
  <!-- endsource: en/_includes/sourcecraft/ci-cd/public-workflow-run-example-api.md -->

{% endlist %}

#### Useful links {#see-also}

* [Configuring a public workflow in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/public-workflows.md)
* [Continuous integration and continuous deployment in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md)
* [CI/CD reference](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/index.md)