Prepare GitHub Actions

This commit is contained in:
cytopia
2020-12-12 13:57:19 +01:00
parent ec8fc4eab6
commit 88aeca57aa
5 changed files with 114 additions and 167 deletions

View File

@@ -3,7 +3,7 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Job Name # Job Name
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
name: PHP-CI name: build
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
@@ -12,55 +12,14 @@ name: PHP-CI
on: on:
# Runs on Pull Requests # Runs on Pull Requests
pull_request: pull_request:
# Runs on Push
# Runs on master Branch and Tags
push: push:
branches:
- master
tags:
- '[0-9]+.[0-9]+*'
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# What to run # What to run
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
jobs: jobs:
diagnostics:
name: Diagnostics
runs-on: ubuntu-latest
strategy:
fail-fast: False
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Show environment
run: |
env
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context
- name: Show GitHub variables
run: |
echo "github.actor: ${{ github.actor }}"
echo "github.ref: ${{ github.ref }}"
echo "github.base_ref: ${{ github.base_ref }}"
echo "github.head_ref: ${{ github.head_ref }}"
echo "github.event: ${{ github.event }}"
echo "github.event_name: ${{ github.event_name }}"
echo "github.event.pull_request.base.repo.id: ${{ github.event.pull_request.base.repo.id }}"
echo "github.event.pull_request.head.repo.id: ${{ github.event.pull_request.head.repo.id }}"
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "${GITHUB_CONTEXT}"
- name: Dump Runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "${RUNNER_CONTEXT}"
build: build:
name: "[ PHP-${{ matrix.version }} ]" name: "[ PHP-${{ matrix.version }} ]"
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -83,7 +42,7 @@ jobs:
steps: steps:
# ------------------------------------------------------------ # ------------------------------------------------------------
# Checkout repository # Setup repository
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
@@ -97,7 +56,7 @@ jobs:
# Retrieve git info (tags, etc) # Retrieve git info (tags, etc)
git fetch --all git fetch --all
# BRANCH, TAG or COMMIT # Branch, Tag or Commit
GIT_TYPE="$( \ GIT_TYPE="$( \
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
| sh \ | sh \
@@ -111,15 +70,25 @@ jobs:
| grep '^GIT_NAME' \ | grep '^GIT_NAME' \
| sed 's|.*=||g' \ | sed 's|.*=||g' \
)" )"
# Docker Tag
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
DOCKER_TAG="${VERSION}"
else
DOCKER_TAG="${VERSION}-${GIT_SLUG}"
fi
# Output # Output
echo "GIT_TYPE=${GIT_TYPE}" echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}" echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
# Export variable # Export variable
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
echo "GIT_TYPE=${GIT_TYPE}" >> $GITHUB_ENV echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
echo "GIT_SLUG=${GIT_SLUG}" >> $GITHUB_ENV echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
env:
VERSION: ${{ matrix.version }}
# ------------------------------------------------------------ # ------------------------------------------------------------
@@ -310,9 +279,8 @@ jobs:
# ------------------------------------------------------------ # ------------------------------------------------------------
# Push build artifacts # Deploy
# ------------------------------------------------------------ # ------------------------------------------------------------
# Only run this, if the PR was created by the repo owner
- name: Publish images (only repo owner) - name: Publish images (only repo owner)
run: | run: |
retry() { retry() {
@@ -328,34 +296,22 @@ jobs:
return 1; return 1;
} }
# Info output # Output
echo "Git Type: ${GIT_TYPE}" echo "GIT_TYPE=${GIT_TYPE}"
echo "Git Slug: ${GIT_SLUG}" echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
docker images
# Login # Login
echo "retry make login USER= PASS=" retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }}
# Push # Push
if [ "${GIT_TYPE}" = "TAG" ]; then echo "retry make push-base VERSION=${DOCKER_TAG}"
echo "retry make push-base VERSION=${VERSION}-${GIT_SLUG}" echo "retry make push-mods VERSION=${DOCKER_TAG}"
echo "retry make push-mods VERSION=${VERSION}-${GIT_SLUG}" echo "retry make push-prod VERSION=${DOCKER_TAG}"
echo "retry make push-prod VERSION=${VERSION}-${GIT_SLUG}" echo "retry make push-work VERSION=${DOCKER_TAG}"
echo "retry make push-work VERSION=${VERSION}-${GIT_SLUG}"
else
if [ "${GIT_SLUG}" = "master" ]; then
echo "retry make push-base VERSION=${VERSION}"
echo "retry make push-mods VERSION=${VERSION}"
echo "retry make push-prod VERSION=${VERSION}"
echo "retry make push-work VERSION=${VERSION}"
else
echo "retry make push-base VERSION=${VERSION}-${GIT_SLUG}"
echo "retry make push-mods VERSION=${VERSION}-${GIT_SLUG}"
echo "retry make push-prod VERSION=${VERSION}-${GIT_SLUG}"
echo "retry make push-work VERSION=${VERSION}-${GIT_SLUG}"
fi
fi
env: env:
VERSION: ${{ matrix.version }}
RETRIES: 20 RETRIES: 20
PAUSE: 10 PAUSE: 10
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
@@ -365,5 +321,5 @@ jobs:
|| ||
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
|| ||
(github.event_name == 'pull_request' && (startsWith(github.head_ref, 'release-'))) (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-'))
) )

View File

@@ -1,27 +1,42 @@
--- ---
### # -------------------------------------------------------------------------------------------------
### Lints all generic and json files in the whole git repository # Job Name
### # -------------------------------------------------------------------------------------------------
name: lint
name: Linting
# -------------------------------------------------------------------------------------------------
# When to run
# -------------------------------------------------------------------------------------------------
on: on:
# Runs on Pull Requests
pull_request: pull_request:
# -------------------------------------------------------------------------------------------------
# What to run
# -------------------------------------------------------------------------------------------------
jobs: jobs:
lint: lint:
name: "[ ${{ matrix.job }} ]" name: "[ ${{ matrix.job }} ]"
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: False
matrix:
job: [gen-dockerfiles]
steps: steps:
# ------------------------------------------------------------
# Setup repository
# ------------------------------------------------------------
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
# ------------------------------------------------------------
# Lint repository
# ------------------------------------------------------------
- name: Lint workflow
id: vars
run: |
make lint-workflow
- name: Diff generated Docker files - name: Diff generated Docker files
run: | run: |
make "${JOB}" make gen-readme
git diff --quiet || { echo "Build Changes"; git diff; git status; false; } git diff --quiet || { echo "Build Changes"; git diff; git status; false; }
env:
JOB: ${{ matrix.job }}

View File

@@ -3,7 +3,7 @@
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# Job Name # Job Name
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
name: PHP-Nightly name: nightly
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
@@ -19,50 +19,8 @@ on:
# What to run # What to run
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
jobs: jobs:
diagnostics: nightly:
name: Diagnostics name: "[ PHP-${{ matrix.version }} ] (ref: ${{ matrix.refs }})"
runs-on: ubuntu-latest
strategy:
fail-fast: False
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Show environment
run: |
env
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context
- name: Show GitHub variables
run: |
echo "github.actor: ${{ github.actor }}"
echo "github.ref: ${{ github.ref }}"
echo "github.base_ref: ${{ github.base_ref }}"
echo "github.head_ref: ${{ github.head_ref }}"
echo "github.event: ${{ github.event }}"
echo "github.event_name: ${{ github.event_name }}"
echo "github.event.pull_request.base.repo.id: ${{ github.event.pull_request.base.repo.id }}"
echo "github.event.pull_request.head.repo.id: ${{ github.event.pull_request.head.repo.id }}"
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "${GITHUB_CONTEXT}"
- name: Dump Runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "${RUNNER_CONTEXT}"
- name: Show git info
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: |
git log | head -20
build:
name: "[ PHP-${{ matrix.version }} (ref: ${{ matrix.refs }}) ]"
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: False fail-fast: False
@@ -82,11 +40,11 @@ jobs:
- '8.1' - '8.1'
refs: refs:
- 'master' - 'master'
- '0.121' - '0.122'
steps: steps:
# ------------------------------------------------------------ # ------------------------------------------------------------
# Checkout repository # Setup repository
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v2
@@ -101,7 +59,7 @@ jobs:
# Retrieve git info (tags, etc) # Retrieve git info (tags, etc)
git fetch --all git fetch --all
# BRANCH, TAG or COMMIT # Branch, Tag or Commit
GIT_TYPE="$( \ GIT_TYPE="$( \
curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \ curl -sS https://raw.githubusercontent.com/cytopia/git-tools/master/git-info.sh \
| sh \ | sh \
@@ -115,15 +73,25 @@ jobs:
| grep '^GIT_NAME' \ | grep '^GIT_NAME' \
| sed 's|.*=||g' \ | sed 's|.*=||g' \
)" )"
# Docker Tag
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_SLUG}" = "master" ]; then
DOCKER_TAG="${VERSION}"
else
DOCKER_TAG="${VERSION}-${GIT_SLUG}"
fi
# Output # Output
echo "GIT_TYPE=${GIT_TYPE}" echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_SLUG=${GIT_SLUG}" echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
# Export variable # Export variable
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#environment-files
echo "GIT_TYPE=${GIT_TYPE}" >> $GITHUB_ENV echo "GIT_TYPE=${GIT_TYPE}" >> ${GITHUB_ENV}
echo "GIT_SLUG=${GIT_SLUG}" >> $GITHUB_ENV echo "GIT_SLUG=${GIT_SLUG}" >> ${GITHUB_ENV}
echo "DOCKER_TAG=${DOCKER_TAG}" >> ${GITHUB_ENV}
env:
VERSION: ${{ matrix.version }}
# ------------------------------------------------------------ # ------------------------------------------------------------
@@ -314,9 +282,8 @@ jobs:
# ------------------------------------------------------------ # ------------------------------------------------------------
# Push build artifacts # Deploy
# ------------------------------------------------------------ # ------------------------------------------------------------
# Only run this, if the PR was created by the repo owner
- name: Publish images (only repo owner) - name: Publish images (only repo owner)
run: | run: |
retry() { retry() {
@@ -332,34 +299,22 @@ jobs:
return 1; return 1;
} }
# Info output # Output
echo "Git Type: ${GIT_TYPE}" echo "GIT_TYPE=${GIT_TYPE}"
echo "Git Slug: ${GIT_SLUG}" echo "GIT_SLUG=${GIT_SLUG}"
echo "DOCKER_TAG=${DOCKER_TAG}"
docker images
# Login # Login
echo "retry make login USER= PASS=" retry make login USER=${{ secrets.DOCKERHUB_USERNAME }} PASS=${{ secrets.DOCKERHUB_PASSWORD }}
# Push # Push
if [ "${GIT_TYPE}" = "TAG" ]; then echo "retry make push-base VERSION=${DOCKER_TAG}"
echo "retry make push-base VERSION=${VERSION}-${GIT_SLUG}" echo "retry make push-mods VERSION=${DOCKER_TAG}"
echo "retry make push-mods VERSION=${VERSION}-${GIT_SLUG}" echo "retry make push-prod VERSION=${DOCKER_TAG}"
echo "retry make push-prod VERSION=${VERSION}-${GIT_SLUG}" echo "retry make push-work VERSION=${DOCKER_TAG}"
echo "retry make push-work VERSION=${VERSION}-${GIT_SLUG}"
else
if [ "${GIT_SLUG}" = "master" ]; then
echo "retry make push-base VERSION=${VERSION}"
echo "retry make push-mods VERSION=${VERSION}"
echo "retry make push-prod VERSION=${VERSION}"
echo "retry make push-work VERSION=${VERSION}"
else
echo "retry make push-base VERSION=${VERSION}-${GIT_SLUG}"
echo "retry make push-mods VERSION=${VERSION}-${GIT_SLUG}"
echo "retry make push-prod VERSION=${VERSION}-${GIT_SLUG}"
echo "retry make push-work VERSION=${VERSION}-${GIT_SLUG}"
fi
fi
env: env:
VERSION: ${{ matrix.version }}
RETRIES: 20 RETRIES: 20
PAUSE: 10 PAUSE: 10
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions # https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
@@ -369,5 +324,5 @@ jobs:
|| ||
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')))
|| ||
(github.event_name == 'pull_request' && (startsWith(github.head_ref, 'release-'))) (github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release-'))
) )

View File

@@ -31,6 +31,8 @@ help:
@echo "Targets" @echo "Targets"
@echo "--------------------------------------------------------------------------------" @echo "--------------------------------------------------------------------------------"
@echo @echo
@echo "lint Lint project files and repository"
@echo
@echo "gen-readme [VERSION=] Update README with PHP modules from built images." @echo "gen-readme [VERSION=] Update README with PHP modules from built images."
@echo "gen-dockerfiles [FAIL_FAST=] Generate Dockerfiles from templates." @echo "gen-dockerfiles [FAIL_FAST=] Generate Dockerfiles from templates."
@echo @echo
@@ -67,6 +69,27 @@ help:
@echo "ARGS Can be added to all build-* and rebuild-* targets" @echo "ARGS Can be added to all build-* and rebuild-* targets"
@echo " to supply additional docker build options." @echo " to supply additional docker build options."
# -------------------------------------------------------------------------------------------------
# Lint Targets
# -------------------------------------------------------------------------------------------------
lint: lint-workflow
lint-workflow:
@\
GIT_CURR_MAJOR="$$( git tag | sort -V | tail -1 | sed 's|\.[0-9]*$$||g' )"; \
GIT_CURR_MINOR="$$( git tag | sort -V | tail -1 | sed 's|^[0-9]*\.||g' )"; \
GIT_NEXT_TAG="$${GIT_CURR_MAJOR}.$$(( GIT_CURR_MINOR + 1 ))"; \
if ! grep 'refs:' -A 100 .github/workflows/nightly.yml \
| grep " - '$${GIT_NEXT_TAG}'" >/dev/null; then \
echo "[ERR] New Tag required in .github/workflows/nightly.yml: $${GIT_NEXT_TAG}"; \
exit 1; \
else \
echo "[OK] Git Tag present in .github/workflows/nightly.yml: $${GIT_NEXT_TAG}"; \
fi
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
# GENERATE TARGETS # GENERATE TARGETS
# ------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------
@@ -83,7 +106,6 @@ else
cd build; ./gen-readme.sh $(VERSION) cd build; ./gen-readme.sh $(VERSION)
endif endif
gen-dockerfiles: gen-dockerfiles:
docker run --rm \ docker run --rm \
$$(tty -s && echo "-it" || echo) \ $$(tty -s && echo "-it" || echo) \

View File

@@ -1,9 +1,8 @@
# PHP-FPM Docker images # PHP-FPM Docker images
[![Linting](https://github.com/devilbox/docker-php-fpm/workflows/Linting/badge.svg)](https://github.com/devilbox/docker-php-fpm/actions?workflow=Linting) [![lint](https://github.com/devilbox/docker-php-fpm/workflows/lint/badge.svg)](https://github.com/devilbox/docker-php-fpm/actions?workflow=lint)
[![CI](https://github.com/devilbox/docker-php-fpm/workflows/PHP-CI/badge.svg)](https://github.com/devilbox/docker-php-fpm/actions?workflow=PHP-CI) [![build](https://github.com/devilbox/docker-php-fpm/workflows/build/badge.svg)](https://github.com/devilbox/docker-php-fpm/actions?workflow=build)
[![Nightly](https://github.com/devilbox/docker-php-fpm/workflows/PHP-Nightly/badge.svg)](https://github.com/devilbox/docker-php-fpm/actions?workflow=PHP-Nightly) [![nightly](https://github.com/devilbox/docker-php-fpm/workflows/nightly/badge.svg)](https://github.com/devilbox/docker-php-fpm/actions?workflow=nightly)
[![Travis](https://travis-ci.org/devilbox/docker-php-fpm.svg?branch=master)](https://travis-ci.org/devilbox/docker-php-fpm)
[![Release](https://img.shields.io/github/release/devilbox/docker-php-fpm.svg?colorB=orange)](https://github.com/devilbox/docker-php-fpm/releases) [![Release](https://img.shields.io/github/release/devilbox/docker-php-fpm.svg?colorB=orange)](https://github.com/devilbox/docker-php-fpm/releases)
[![Gitter](https://badges.gitter.im/devilbox/Lobby.svg)](https://gitter.im/devilbox/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Gitter](https://badges.gitter.im/devilbox/Lobby.svg)](https://gitter.im/devilbox/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Discourse](https://img.shields.io/discourse/https/devilbox.discourse.group/status.svg?colorB=%234CB697)](https://devilbox.discourse.group) [![Discourse](https://img.shields.io/discourse/https/devilbox.discourse.group/status.svg?colorB=%234CB697)](https://devilbox.discourse.group)