---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/gh-actions.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/concepts/gh-actions.md
  - href: https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/gh-actions.md
    type: text/markdown
    title: Markdown version
  - href: https://sourcecraft.dev/portal/docs/en/llms.txt
    type: text/markdown
    title: llms.txt
title: Integration with GitHub Actions in SourceCraft
description: How to use GitHub Actions in SourceCraft CI/CD workflows to automate builds and testing.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Integration with GitHub Actions in SourceCraft

<!-- source: en/_includes/sourcecraft/ci-cd/gh-actions-intro.md -->
SourceCraft [CI/CD](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md) workflows support [GitHub Actions](https://docs.github.com/en/actions).

_GitHub Actions_ is GitHub's native CI/CD platform that enables you to create, set up, and run workflows to automate builds, testing, deployment, and other tasks within the software lifecycle as well as reuse these workflows across repositories.

You can integrate both custom and public GitHub Actions available in the [GitHub Marketplace](https://github.com/marketplace?type=actions) into your SourceCraft CI/CD [workflows](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#workflows).

To work with GitHub Actions in SourceCraft, you do not need to create a GitHub account or use the GitHub interface.
<!-- endsource: en/_includes/sourcecraft/ci-cd/gh-actions-intro.md -->

<!-- source: en/_includes/sourcecraft/ci-cd/gh-gl-cloud-workers.md -->
{% note warning %}

Only [cloud workers](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/workers.md#cloud-workers) support running GitHub Actions or GitLab pipelines in SourceCraft CI/CD.

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/ci-cd/gh-gl-cloud-workers.md -->

For integration with GitHub Actions, SourceCraft uses a special [cube](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#cubes) with the `action` and (optionally) `with` parameters:

<!-- source: en/_includes/sourcecraft/ci-cd/gh-actions-template.md -->
```yaml
on:
  push:
    - workflows: [test-workflow]
      filter:
        branches: ["main"]

workflows:
  test-workflow:
    tasks:
      - name: demo-github-action-ci
        cubes:
          - name: run-github-action
            action: <GitHub_Action_name>@<version>
            with:
              <GitHub_Action_parameter_1>: <value_1>
              <GitHub_Action_parameter_2>: <value_2>
              ...
```
<!-- endsource: en/_includes/sourcecraft/ci-cd/gh-actions-template.md -->

<!-- source: en/_includes/sourcecraft/ci-cd/gh-actions-example.md -->
The example below shows a `.sourcecraft/ci.yaml` configuration file that describes the following steps:

* Obtaining an IAM token for Yandex Cloud using a [service connection](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/service-connections.md).
* Installing [Docker Buildx](https://github.com/docker/buildx) in the [worker](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/workers.md) environment using the [Docker Setup Buildx](https://github.com/marketplace/actions/docker-setup-buildx) GitHub Action.
* Authenticating with [Yandex Cloud Registry](https://yandex.cloud/en/docs/cloud-registry/) using the [Docker Login](https://github.com/marketplace/actions/docker-login) GitHub Action and the Yandex Cloud IAM token.
* Building a Docker image from the `Dockerfile` located at the repository root and pushing it to Cloud Registry using the [Build and push Docker images](https://github.com/marketplace/actions/build-and-push-docker-images) GitHub Action.

```yaml
tokens:
  # Token name (can be any).
  <token_name>:
    # Name of the service connection to Yandex Cloud
    service_connection: <service_connection_name>
    # Requested access scope:
    # org: All repositories
    # repo: Specific repository
    # ref: Branch or tag
    scope: repo

workflows:
  test-workflow:
    tasks:
      - name: test-gh-actions-task
        cubes:
          # The cube exchanges the SourceCraft token for the Yandex Cloud IAM token
          # and saves it to the `IAM_TOKEN` variable within the `outputs` section.
          - name: get-iam-token
            env:
              ID_TOKEN: ${{ tokens.<token_name>.id_token }}
              YC_SA_ID: ${{ tokens.<token_name>.service_account_id }}
            image: cr.yandex/sourcecraft/yc-iam:latest

          # The cube installs and configures the Docker Buildx utility.
          - name: setup-buildx
            action: docker/setup-buildx-action@v3.11.1

          # The cube authenticates with Yandex Cloud Registry 
          # using the IAM token.
          - name: login
            action: docker/login-action@v3.5.0
            with:
              registry: cr.yandex/<registry_ID>
              username: iam
              # Substitute to the `outputs` section the name of the IAM token cube,
              # e.g., `get-iam-token`.
              password: ${{ cubes.<IAM_token_cube_name>.outputs.IAM_TOKEN }}

          # The cube builds the Docker image from the Dockerfile and pushes it to the registry in
          # Cloud Registry.
          - name: build-and-push
            action: docker/build-push-action@v6.18.0
            with:
              context: .
              file: Dockerfile
              platforms: linux/amd64
              tags: |
                cr.yandex/<registry_ID>/image-name:latest
              push: true

on:
  push: test-workflow
```
<!-- endsource: en/_includes/sourcecraft/ci-cd/gh-actions-example.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 -->

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

* [Using GitHub Actions in SourceCraft CI/CD](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/gh-actions.md)
* [Setting up CI/CD to deploy an application to Yandex Serverless Containers using GitHub Actions](https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/ci-cd-sourcecraft-github-actions.md)
* [GitLab pipelines in the SourceCraft CI/CD](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/gl-pipelines.md)
* [Using GitLab pipelines in the SourceCraft CI/CD](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/gl-pipelines.md)
* [Continuous integration and continuous deployment in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md)
* [Service connections SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/service-connections.md)