Introducción Practica a Github Actions
En este tutorial haremos:
- Crea un repositorio en Github
- Crea un Github Action Workflow
- Clonalo
y añade la siguiente configuracion:
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
env:
plataform: AWS
region: us-east-1
account: 123456789012
steps:
- name: Display custom env vars
run: |
echo "Plataform: ${{ env.plataform }}"
echo "Region: ${{ env.region }}"
echo "Account: ${{ env.account }}"
Condicionales
Tambien podemos colocar condicionales
env:
platform: AWS
region: us-east-1
account: 123456789012
steps:
- name: Display custom env vars
if: ${{ env.platform == 'AWS' }}
run: |
echo "Plataform: ${{ env.platform }}"
echo "Region: ${{ env.region }}"
echo "Account: ${{ env.account }}"
Eventos por defecto
- name: Display the event
run: |
echo "Event: ${{ toJson(github.event) }}"
O muestra eventos individuales
- name: default env vars
run: |
echo "GITHUB_ACTOR: $GITHUB_ACTOR"
echo "GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
Secrets
Para evitar escribir las variables de entorno podemos usar los Secrets de Github
env:
platform: ${{ secrets.PLATFORM }}
region: ${{ secrets.REGION }}
account: ${{ secrets.ACCOUNT }}
steps:
- name: Display custom env vars
run: |
echo "Plataform: ${{ env.platform }}"
echo "Region: ${{ env.region }}"
echo "Account: ${{ env.account }}"
echo "Plataform: ${{ secrets.PLATFORM }}"
echo "Region: ${{ secrets.REGION }}"
echo "Account: ${{ secrets.ACCOUNT }}"
echo "Platform: ${{ vars.TEST }}"
echo "Region: ${{ vars.NAME}}"