Dev Conventions
  • Dev Conventions
  • Git
    • Branch Flow
    • Conventional Commits
    • Pull requests template
    • Before making the PRs in typescript, keep in mind
  • Typescript
    • Introduction
    • Good practices
    • Solid
    • Using pnpm for Package Management
    • NestJs
    • NextJs
    • React
    • NestJs Testing
    • React Testing
    • Npm Registry
  • PYTHON
    • Introduction
    • Good practices
    • Testing
    • Naming Convention
  • DevOps
    • Introduction
    • Github Actions
    • Creating a Github Actions Workflow
  • Agile
    • Story Points
Powered by GitBook
On this page
  • How GitHub Actions Works
  • Creating a Workflow in GitHub Actions
  • Important Considerations
  • Conclusion
  1. DevOps

Creating a Github Actions Workflow

💡GitHub Actions is a powerful tool integrated directly into GitHub that allows you to automate workflows within your repositories.

These workflows can include everything from automated tests and deployments to any type of custom action you want to execute in response to specific events in your repository.

How GitHub Actions Works

GitHub Actions is based on workflows configured using YAML files that define the actions to execute and the events that trigger those actions.

These workflows can be triggered by events such as push, pull request, issue creation, among others.

Creating a Workflow in GitHub Actions

  1. Create a YAML file:

    Workflows are defined in YAML files that must be located in the .github/workflows folder within your repository.

    name: CI
    
    on:
      push:
        branches:
          - main
      pull_request:
        branches:
          - main
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
          - uses: actions/checkout@v2
          - name: Install dependencies
            run: npm install
          - name: Run tests
            run: npm test

    This example defines a workflow called "CI" that runs automated tests when a push or pull request is made to the main branch (main).

  2. YAML File Syntax:

    YAML files specify the actions (steps) to be executed under certain conditions (on). They can include pre-defined GitHub actions (uses) or custom actions.

  3. Location of YAML Files:

    Workflow YAML files are stored in the .github/workflows directory within the repository. GitHub automatically detects these files and uses them to configure the workflows.

  4. Running and Testing Locally:

    GitHub Actions does not natively run locally, but you can simulate its operation using tools like act (https://github.com/nektos/act).

    act allows you to run the workflows defined in GitHub Actions YAML files locally, using Docker containers to simulate the execution environment.

    Example of using act:

    act -s GITHUB_TOKEN=<your_token>

    <your_token> should be a GitHub personal access token with the appropriate permissions to access the repository.

Important Considerations

  • Security: Use secret environment variables (secrets) to store sensitive information such as API tokens or access keys.

  • Reusability: You can create custom actions that encapsulate common functionalities for reuse in different workflows.

  • Scalability: GitHub Actions automatically scales according to the execution needs of the workflows, allowing parallelism and efficient resource management.

Conclusion

GitHub Actions is a versatile tool that facilitates the automation of processes within your development workflow.

From automated testing to continuous deployments, GitHub Actions offers an integrated and powerful solution to improve the efficiency and quality of software development.

PreviousGithub ActionsNextStory Points

Last updated 11 months ago

For more technical details and advanced examples, refer to the .

official GitHub Actions documentation