Skip to content

Latest commit

 

History

History
595 lines (452 loc) · 11.9 KB

slides.md

File metadata and controls

595 lines (452 loc) · 11.9 KB
theme highlighter transition mdc presenter title addons fonts themeConfig layout image
the-unnamed
shiki
slide-left
true
dev
From Code to Cloud: Automated Deployments with GitHub Actions
slidev-addon-components
sans
Lato,cursive
color background font-size cover-background cover-headingBg cover-headingColor default-background default-headingBg default-headingColor default-font-size center-background center-headingBg center-headingColor section-background section-headingBg section-headingColor aboutme-background aboutme-color aboutme-helloBg aboutme-helloColor aboutme-nameColor code-background code-color code-font-size
#000000
#215287
2em
#ffffff
#215287
#F8F8F8
#F8F8F8
#215287
#F8F8F8
1.4rem
#F8F8F8
#215287
#F8F8F8
#F8F8F8
#215287
#F8F8F8
#F8F8F8
var(--slidev-theme-color)
#215287
#F8F8F8
#215287
#215287
#F8F8F8
1.1em
image
./cloudsummit/title.png

layout: image image: ./cloudsummit/sponsor.png


layout: about-me imageSrc: ./profile/eliostruyf_2023.jpg helloMsg: 👋 Hello! name: Elio Struyf job: Struyf Consulting line1: "#Stickerpreneur @ pyod.shop" line2: "#Maintainer @ Front Matter CMS" social1: "@eliostruyf" social2: eliostruyf.com social3: elio@struyfconsulting.be


layout: cover background: ./slides/githubactions.svg

Understanding GitHub Actions:
Fundamentals and terminology

<style> h1 { font-size: 3.5rem !important; } </style>

What are GitHub Actions?

  • CI/CD service
  • Automate builds, tests, deployments, issues, etc.
  • Workflow defined in YAML
  • Triggers based on events like push, pull requests, etc.
  • Actions are reusable tasks
  • Runners are VMs to execute workflows on Windows, macOS, Linux


Why GitHub Actions?

  • Integrated with GitHub
  • Free for public repositories and self-hosted runners
  • Community contributed actions
  • Cost-effective for private repositories ("free" minutes)


"Free" minutes per plan

Plan Free minutes
GitHub Free 2,000
GitHub Pro 3,000
GitHub Free for orgs 2000
GitHub Team 3,000
GitHub Enterprise Cloud 50,000

layout: cover background: ./slides/warning.jpg

Mind the minute multipliers!!!

<style> h1::before { background: #EE4266 !important; } </style>

Minute what?

macOS and Windows runners are more expensive


Runner Multiplier
Linux 1x
Windows 2x
macOS 10x

Large runners are more expensive (only for orgs and enterprises)


layout: cover background: ./slides/terminology.jpg

GitHub Actions Terminology



GitHub Actions Terminology

flowchart LR
  Events --> |triggers| Workflow --> |starts| Job --> |uses| Runner --- Step --- Action
Loading

  • Event: Trigger for a workflow
  • Workflow: Automation process
  • Job: Set of steps that execute on the same runner
  • Runner: VM to execute workflows
  • Step: A task that can run commands
  • Action: A reusable task


Types of event triggers

  • push: Triggered on push to a branch
  • pull_request: Triggered on pull request
  • schedule: Triggered on a schedule
  • release: Triggered on release
  • workflow_call: Triggered by another workflow
  • workflow_dispatch: Triggered manually
  • repository_dispatch: Triggered by an external event

More triggers



GitHub Actions Workflow

Create a .github/workflows directory in your repository.

name: Build and Deploy
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm install
      - run: npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist

layout: cover background: ./slides/craft.jpg

Building Blocks:
Crafting your first GitHub Actions workflow


Variables

  • Non-sensitive configuration information
  • Levels:
    • Workflow: env
    • Repository
    • Environment
    • Organization
  • Default environment variables: GITHUB_* and RUNNER_*
    • GITHUB_REPOSITORY: owner/repo
    • GITHUB_REPOSITORY_OWNER: owner


Highlights

  1. Workflows created in .github/workflows directory
  2. Define workflow variables by using env
  3. Actions options can be added like with, env, etc.
  4. Variables and contexts can be used in the workflow
  5. Setting your variables like with >> $GITHUB_ENV
echo "{environment_variable_name}={value}" >> $GITHUB_ENV

GitHub Variables - GitHub Context


layout: cover background: ./slides/deploy.jpg

From Artifact to Deployment:
Deploy your website



Automatic token authentication

  • Each workflow job creates a GITHUB_TOKEN secret
  • Used to authenticate with GitHub API
  • ${{ secrets.GITHUB_TOKEN }}

Comes with default permissions depending on the repo settings



Elevate the GITHUB_TOKEN permissions

preview-deploy:
  runs-on: ubuntu-latest
  needs: build

  permissions:
    contents: read
    pages: write
    id-token: write


Job output variables

Step 1: Set the variable

    steps:
      - id: step1 # Required
        run: |
          # {name}={value}
          echo "website=https://..." >> $GITHUB_OUTPUT

Step 2: Define the output

jobs:
  job1:
    outputs:
      website: ${{ steps.step1.outputs.website }}

Step 3: Use the output

  job2:
    needs: job1
    steps:
      - run: echo ${{ needs.job1.outputs.website }}


Highlights

  • You can depend on other jobs by using the needs key
  • Use the actions/upload-artifact action to upload artifacts
  • Permissions on the GITHUB_TOKEN can be changed
  • Set job output variables with >> $GITHUB_OUTPUT
  • Add information to the job summary via >> $GITHUB_STEP_SUMMARY

layout: cover background: ./slides/testing.jpg

Ensuring Success:
Validating the deployment



Caching dependencies

Use actions/cache to cache dependencies

- name: Cache Playwright
  id: cache-playwright
  uses: actions/cache@v4
  with:
    path: ~/.cache/ms-playwright
    key: playwright-${{ env.PLAYWRIGHT_VERSION }}


Conditions

Conditions can be added to jobs and steps to control when they run

- name: Install Playwright Browsers
  if: steps.cache-playwright.outputs.cache-hit != 'true'
  run: npx playwright install --with-deps

  • if: always() to always run the step (even if the previous step/job failed)
  • Functions: contains(), startsWith(), endsWith(), ...

Highlights

  • Use actions/cache to cache dependencies
  • Conditions can be added to jobs and steps to control when they run
  • Each environment can have its variables and secrets
    • Using variables: vars.{name}
    • Using secrets: secrets.{name}

layout: cover background: ./slides/azure.jpg

Expanding Horizons:
Using environments



Environments

  • Used for a deployment target
  • Allow you to set environment-specific variables/secrets
  • Wait timer can be set
  • Protection rules can be set
    • You can set an approval/review process
    • Limit branches/tags per environment

jobs:
  production-deploy:
    runs-on: ubuntu-latest
    environment:
      name: azure

Secrets

  • Sensitive information
  • Levels:
    • Repository
    • Environment
    • Organization
  • Access policy on organization-level
  • Values are masked in build outputs
  • Set as input or environment variable to use them


Highlights

  • Use environment-specific variables and secrets
  • Reuse actions with custom actions
  • Set an approval process for the deployment
  • Set secrets.{name} to use the secret in the workflow

layout: cover background: ./slides/ideas.jpg

There is a lot more to discover



Debugging

  • Detailed logging via ACTIONS_RUNNER_DEBUG secret/variable is true
  • Enable debug logging on workflow re-run



There is still more to explore


layout: default background: ./slides/thankyou.jpg

Slides: github-actions.elio.dev

<style> .slidev-layout.default { background: url(./slides/thankyou.jpg) no-repeat center center !important; position: relative; } h1 { position: absolute !important; bottom: 0.5rem; left: 7rem; color: #000 !important; } h1::before { background: #84DFD2 !important; } </style>

layout: about-me imageSrc: ./profile/eliostruyf_2023.jpg helloMsg: The end! 👋 name: Elio Struyf job: Struyf Consulting line1: "#Stickerpreneur @ pyod.shop" line2: "#Maintainer @ Front Matter CMS" social1: "@eliostruyf" social2: eliostruyf.com social3: elio@struyfconsulting.be