GitHub Actions Overview
● Feature that allows GitHub users to create
automated pipelines that can be triggered by
events or run on schedule
● Popular for CI/CD
● Open source repos get unlimited action runs for
free
● The GitHub Marketplace has a large collection of
ready-to-use Actions contributed by the
community
Slide 4
Slide 4 text
GitHub Actions Overview
● Common use cases: run tests and code
quality checks on merge / PR etc
● Less common use cases: something like
Dynacover
Actions
● Self-contained units of execution that can be
combined in workflows
● Actions live in dedicated repositories with an
action.yml file that defines its configuration
● You can combine actions from the
marketplace with your own custom actions
● Actions must be packaged as Docker images
Slide 7
Slide 7 text
Workflows
● A configurable process that runs one or more
jobs
● Each job can have multiple steps
● Steps can be either an Action or a shell script
● Steps run in order and share data
● Jobs run in parallel unless otherwise specified
● Defined in a YAML file committed to the
repository
● You can have several different workflows in the
same repository
Slide 8
Slide 8 text
Workflow Example: PHP Composer
name: PHP Composer
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run test suite
run: composer test
Slide 9
Slide 9 text
Triggers
● Workflows can be triggered by events such as
new commits, new issues, when a PR is
created, etc
● Workflows can also run on schedule, similar to
cron jobs
● When on schedule, the minimal interval is five
minutes
Slide 10
Slide 10 text
Action Secrets
● Encrypted environment variables
accessible only by GitHub Actions
● Can be set at repository level or per
environment
● Ideal for storing API keys and auth
tokens
Slide 11
Slide 11 text
2. Minicli Overview &
The Demo App
Slide 12
Slide 12 text
Minicli Overview
● Microframework for CLI PHP apps
● Simple command architecture
● Commands defined as callback (single-file
app) or controllers (structured app)
● Dependency-free (except for tests)
● Ideal for small cron jobs, bots, simple
workers
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
The Demo app
Slide 15
Slide 15 text
3. Turning a Minicli app into a
GitHub Action
Slide 16
Slide 16 text
Preparation
● What will trigger this action?
● Do I need to combine this action with others?
● Do I need to use repository secrets or environment variables to configure my
action?
● If my action creates output that needs to be persisted, where this content goes?
Slide 17
Slide 17 text
Packaging Minicli with Docker
FROM php:8.1-cli
RUN apt-get update && apt-get install -y git curl libxml2-dev zip unzip
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN mkdir /application
COPY . /application/
RUN cd /application && composer install
ENTRYPOINT [ "php", "/application/minicli" ]
CMD ["import", "dev"]
Slide 18
Slide 18 text
The action.yml file
name: 'Import DEV.to posts'
description: 'Imports posts from DEV.to as markdown files'
outputs:
response:
description: 'Output from command'
runs:
using: 'docker'
image: 'Dockerfile'
Slide 19
Slide 19 text
Tagging your action
git add .
git commit -m "My first action is ready"
git tag -a -m "My first action release" v1
git push --follow-tags
Slide 20
Slide 20 text
Creating a Workflow
name: Import posts from DEV
on:
schedule:
- cron: "0 1 * * *"
workflow_dispatch
:
jobs:
main:
runs-on: ubuntu-latest
steps:
(...)
Slide 21
Slide 21 text
Creating a Workflow: Steps
- uses: actions/checkout@v2
- uses: erikaheidi/[email protected]
name: "Import posts from DEV"
env:
DEVTO_USERNAME: erikaheidi
APP_DATA_DIR: ${{ github.workspace }}/devto
- name: Create a PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: Import posts from DEV
title: "[automated] Import posts from DEV"
token: ${{ secrets.GITHUB_TOKEN }}
Slide 22
Slide 22 text
Complete workflow for reference
Slide 23
Slide 23 text
Testing the workflow
Slide 24
Slide 24 text
No content
Slide 25
Slide 25 text
References / Useful Links
● ImportDevTo Action Repository
○ https://github.com/erikaheidi/importDevTo
● How to Create a GitHub Action to Import Posts from DEV to a Repository you Own (tutorial)
○ https://bit.ly/38nANwc
● GitHub Actions documentation
○ https://docs.github.com/en/actions
● Minicli documentation
○ https://docs.minicli.dev
● Other actions built with Minicli
○ Dynacover: https://github.com/erikaheidi/dynacover-actions
○ Update CONTRIBUTORS: https://github.com/minicli/action-contributors