> For the complete documentation index, see [llms.txt](https://kdongs.gitbook.io/kdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kdongs.gitbook.io/kdocs/github/git-actions.md).

# Git Actions

## [About](https://docs.github.com/en/actions/about-github-actions/understanding-github-actions)

It is a workflow automator. It uses the main generated Github events to execute many different tasks, including CI/CD pipelines.

### Main `CI` processes

* Execute tests;
* Linter the code;
* Check code quality, reduce Code Smells, etc;
* Security checks *(like forgotten passwords or tokens on the code)*;
* Generate artifacts for deploy *(like zip files with executable, or docker images)*;
* Identify the next Version to be generated *(like* [Broken mention](broken://pages/Y65Cg9Mj9vNW9pED9tbK)*)*;
* Generate tags and releases. *(like analyze* [Broken mention](broken://pages/5Z9z8HuVAh1A9G1dTQej) *to auto generate Tags and Releases, based on the Commits history)*

## Git Actions Components

A repository can have multiple **workflows**, that triggers based on **events** on the repository, or manually triggered, or at a [defined schedule](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule), or by [posting to a Rest API](https://docs.github.com/en/rest/repos/repos#create-a-repository-dispatch-event).

**Workflows** contain one or more **jobs** that can run in sequencial order or in parallel.

Each **Job** will run inside its own virtual machine Runner or container and can have one or more **Steps**.

Each **Step** runs either a **script** or an **action** *(reusable extensions)*.

<img src="https://835599762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuG4Pb45rgHjFfVnO5BLD%2Fuploads%2F0KK42KBe48FY0VM3jgX7%2Ffile.excalidraw.svg?alt=media&amp;token=f88d094a-416c-4cf7-9bf0-2f59b2371ba9" alt="" class="gitbook-drawing">

### Workflows

A workflow is a `.yaml` file that is created in the project's `/.github/workflows` folder.

You can reference a workflow within another workflow.

Inside workflows you can:

* Run [scripts](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/adding-scripts-to-your-workflow);
* Filter execution [over branches, file paths, or commit messages](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore);
* Use [GitHub secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) to access passwords;
* Use [variables](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables);
* Use [expressions](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions);
* Use [context variable](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs);
* And [others...](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-jobs-in-a-workflow)

{% hint style="danger" %}
**When including paths:**

If a workflow is skipped due to **path filtering**, **branch filtering**, or a **commit message**, then checks associated with that workflow will remain in a "Pending" state.

A pull request that requires those checks to be successful will be blocked from merging.

Read more [here](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-including-paths).
{% endhint %}

{% hint style="success" %}
Check `.yaml` file syntax [here](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions).
{% endhint %}

#### Example

{% code title="ci.yaml" %}

```yaml
name: angular-ci-workflow
on:
  pull_request:
    branches:
      - main
      - develop
jobs:
  test-angular:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Starting Job"
      - run: echo "Trigger: (${{ github.event_name }}), Branch: (${{ github.ref }})"
      # Very common action to checkout your code to the container so it can use it
      - name: Checkout code
        uses: actions/checkout@v2
      # Will run an action specific for Angular, more details at its repository
      - name: Angular CI
        uses: colbyhill21/angular-full-ci/@v1.0
        with:
          testcommand: run test:ci
      - run: echo "Job finished with status ${{ job.status }}"
```

{% endcode %}

### Events

Events are specific activities in a repository that triggers a workflow run.

Check a complete list of [events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows).

### Jobs

Are a set of steps that are executed on the same runner and can share data from one step to another.

Steps are executed in order and are dependent on each other.

{% hint style="warning" %}
You can configure dependencies between jobs.

By default, jobs have no dependency and run in parallel.
{% endhint %}

#### Runner

Each job execute in a separate Runner.

There are Linux, Windows and MacOS runners to run jobs.

### Actions

Are custom application for GitHub Actions plataform that perfoms a complex but repeated task.

{% hint style="info" %}
They are like Docker images, reusable base tasks that were done and shared by other.

Check action in [GitHub Marketplace](https://github.com/marketplace).
{% endhint %}

You can also write your own actions.
