/ps-github-actions

Teaching how Github Actions work

Primary LanguageAstroMIT LicenseMIT

GitHub Actions PS

O que são as Actions?

"GitHub Actions é uma plataforma de integração contínua e entrega contínua (CI/CD) que permite automatizar a sua compilação, testar e pipeline de implantação. É possível criar fluxos de trabalho que criam e testam cada pull request no seu repositório, ou implantar pull requests mesclados em produção. 1"

Utilidades & vantagens

Exemplos

Preço

Tabela de preços do GitHub Actions

Máquina

image

Anatomia

As actions utilizam a sintaxe de arquivos yml para seu funcionamento

name: Release

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

jobs:
  release:
    name: Release

    strategy:
      matrix:
        os: ['ubuntu-latest', 'windows-latest']
     runs-on: ${{ matrix.os }} 

    - name: Lint
      run: yarn lint

    - name: Release
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        GIT_CREDENTIALS: ${{ secrets.GIT_CREDENTIALS }}
      run: npx semantic-release

Exemplo prático

Vamos rodar uma action que faça um deploy automático de um site usando Astro dentro do GitHub Pages

name: Build and deploy

on:
  push:
    branches:
      - main
  workflow_dispatch:
  

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "lts/*"

      - name: GitHub Action for Yarn
        uses: Borales/actions-yarn@v4.2.0
        with:
          cmd: install --frozen-lockfile

      - name: Build Astro
        run: yarn build

      - name: Upload Pages Artifact
        uses: actions/upload-pages-artifact@v1
        with:
          path: ./dist

  deploy:
    name: Deploy
    
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
      
    permissions:
      contents: read
      pages: write
      id-token: write
      
    runs-on: ubuntu-latest
    needs: [build]
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1
      

Footnotes

  1. https://docs.github.com/pt/actions/learn-github-actions/understanding-github-actions