---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/public-workflows.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/public-workflows.md
  - href: https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/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: Configuring a public workflow in SourceCraft
description: How to configure public CI/CD workflows that all organization members can run in SourceCraft.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Configuring a public workflow in SourceCraft

<!-- 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 -->

<!-- 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 -->

To configure a public workflow:
1. [Create a public workflow](#create).
1. [Run the public workflow](#run).

## Creating a public workflow {#create}

{% note info %}

This section of the tutorial is for users creating a public workflow and holding the `Repository developer` minimum [role](https://sourcecraft.dev/portal/docs/en/sourcecraft/security/index.md#src-repositories-developer).

{% endnote %}

1. If you do not have a repository yet, [create](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/repo-create.md) one.
1. [Add](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/add-file-repo.md) the `.sourcecraft/ci.yaml` file with your workflow contents to the repository `main` branch, like this:

    <!-- 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 -->

    Where `settings:shared: true` grants the permission to run the workflow to all organization members.

    <!-- 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 -->

## Running a public workflow {#run}

{% note info %}

This section of the tutorial is for organization members running a public workflow.

{% endnote %}

<!-- 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 -->

{% list tabs group=instructions %}

- CI/CD {#ci-cd}

  1. If you do not have a repository yet, [create](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/repo-create.md) one.
  1. [Add](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/add-file-repo.md) the `.sourcecraft/ci.yaml` file with the workflow contents to the repository `main` branch; this file will run the public workflow. Here is an example:

      <!-- 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 -->

      According to the CI/CD configuration, changes to the branch will trigger the workflow to run automatically. Alternatively, you can [run](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/run-workflow-manually.md) it manually.

      <!-- 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 -->

  1. Check the CI process:
      1. Under ![image](../../_assets/console-icons/terminal-line.svg) **CI/CD** on the repository page, go to ![image](../../_assets/console-icons/arrows-3-rotate-right.svg) **CI/CD**.
      1. Open a running workflow.

          The page that opens will display the workflow tasks, cubes (task steps), as well as statuses and execution results.
      1. In the bottom-right corner of the `run-shared-workflow` cube, click ![image](../../_assets/console-icons/file-text.svg).
      1. Wait for the workflow to complete.

- 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}

* [Public workflows in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/public-workflows.md)
* [Configuring CI/CD in a SourceCraft repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/ci-cd.md)
* [CI/CD reference](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/index.md)
