Простая заготовка для github action
Создаем файлик в репо
vim .github/workflows/demo.yml
И пишем
name: GitHub Actions
run-name: ${{ github.actor }} is testing out GitHub Actions
on: [push]
jobs:
one:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
changedfiles:
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
ts: ${{ steps.changes.outputs.ts }}
steps:
# Make sure we have some code to diff.
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get changed files
id: changes
# Set outputs using the command.
run: |
echo "::set-output name=ts::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.before }} ${{ github.sha }} | grep .swift$ | xargs)"
lint:
runs-on: ubuntu-latest
# require the first job to have ran
needs: changedfiles
# only run there are changed files
if: ${{needs.changedfiles.outputs.ts}}
steps:
- name: echo changed files
run: echo ${{needs.changedfiles.outputs.ts}}
Тут job “one” – просто распечатывает весь json data event, который приходит из Gighub
А вот “lint” запустится только тогда, когда в будет изменен любой файл с расширением .swift (grep .swift$)
PS: Нужно помнить что ::set-output name=ts:: скоро будет отключен
PS1: github.event.before работает только для push, для pull_request нужно использовать github.event.pull_request.base.sha