0% found this document useful (0 votes)
33 views

Github Actions

Resumo da aula de github actions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Github Actions

Resumo da aula de github actions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Github Actions

1. Workflow Configuration:
Workflows are defined in YAML files in the .github/workflows
directory
Workflow files have a .yml or .yaml extension

name: CI language-yaml

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
echo "Running tests..."

2. Triggers:
Trigger workflows based on events like push , pull_request ,
schedule , etc.

on: language-yaml
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 0 * * *'

3. Jobs and Steps:


Jobs define a set of steps that execute on the same runner
Steps can run commands or use actions

jobs: language-yaml
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test

4. Runners:
Specify the runner environment for each job using runs-on

jobs: language-yaml
build:
runs-on: ubuntu-latest

5. Actions:
Use pre-built actions from the GitHub Actions Marketplace or
create custom actions
Reference actions using the uses keyword

steps: language-yaml
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'

6. Environment Variables:
Set environment variables for steps using env

steps: language-yaml
- name: Set environment variable
env:
API_KEY: ${{ secrets.API_KEY }}

7. Secrets:
Store sensitive information as encrypted secrets in the
repository settings
Access secrets using the secrets context

steps: language-yaml
- name: Access secret
run: echo ${{ secrets.API_KEY }}

8. Conditions:
Use conditions to control the execution of steps or jobs

steps: language-yaml
- name: Run only on main branch
if: github.ref == 'refs/heads/main'
run: echo "Running on main branch"

9. Matrix Builds:
Run jobs with different configurations using a matrix

jobs: language-yaml
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

10. Artifacts:
Upload and download build artifacts

steps: language-yaml
- uses: actions/upload-artifact@v2
with:
name: my-artifact
path: build/
- uses: actions/download-artifact@v2
with:
name: my-artifact

Remember to explore the GitHub Actions Marketplace


(https://github.com/marketpl
ace?type=actions) for a wide range of pre-built actions that can
streamline
your workflows. You can find actions for various tasks, such as
building,
testing, deploying, and more.

Refer to the GitHub Actions documentation


(https://docs.github.com/en/actions) for more detailed information on
workflow syntax, contexts, expressions, and other advanced features.

Regularly review and update your workflows to ensure they are up to date
with
the latest best practices and security recommendations.

You might also like