glances/.github/workflows/build.yml

125 lines
3.7 KiB
YAML
Raw Normal View History

2021-04-20 14:14:52 +00:00
# This pipeline aims at building Glances for the following targets:
# - Docker Hub
# - Pypi
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
name: CI
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
env:
DEFAULT_DOCKER_IMAGE: nicolargo/glances
NODE_ENV: ${{ (contains('refs/heads/master', github.ref) || startsWith(github.ref, 'refs/tags/v')) && 'prod' || 'dev' }}
PUSH_BRANCH: ${{ 'refs/heads/develop' == github.ref || 'refs/heads/master' == github.ref || startsWith(github.ref, 'refs/tags/v') }}
DOCKER_PLATFORMS: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386
on:
pull_request:
branches: [ develop ]
push:
branches: [ master, develop ]
tags:
- v*
2021-04-20 08:09:31 +00:00
jobs:
2021-04-20 14:14:52 +00:00
buildx:
2021-04-20 08:09:31 +00:00
runs-on: ubuntu-latest
steps:
2021-04-20 14:14:52 +00:00
- name: Checkout
uses: actions/checkout@v2
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
- name: Cache Docker layers
uses: actions/cache@v2
2021-04-20 08:09:31 +00:00
with:
2021-04-20 14:14:52 +00:00
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.NODE_ENV }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.NODE_ENV }}
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
- name: Configure ENVs
env:
DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE || env.DEFAULT_DOCKER_IMAGE }}
DOCKERFILE: ${{ env.NODE_ENV == 'prod' && './docker-files/Dockerfile' || './docker-files/dev.Dockerfile' }}
run: |
ls -la /tmp/.buildx-cache || true
VERSION=latest
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
if [[ $GITHUB_REF == refs/heads/develop ]]; then
VERSION=dev
fi
echo "DOCKERFILE=${DOCKERFILE}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "TAGS=${DOCKER_IMAGE}:${VERSION}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
echo "VCS_REF=${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
2021-04-20 08:09:31 +00:00
with:
2021-04-20 14:14:52 +00:00
platforms: all
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
- name: Login to DockerHub
uses: docker/login-action@v1
if: ${{ env.PUSH_BRANCH == 'true' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2
with:
push: ${{ env.PUSH_BRANCH == 'true' }}
tags: ${{env.TAGS}}
build-args: |
VERSION=${{env.VERSION}}
BUILD_DATE=${{env.BUILD_DATE}}
VCS_REF=${{env.VCS_REF}}
context: .
file: ${{env.DOCKERFILE}}
platforms: ${{env.DOCKER_PLATFORMS}}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
2021-04-20 08:09:31 +00:00
2021-04-20 14:14:52 +00:00
- name: Install pip install build tools
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution package to Test PyPI
uses: pypa/gh-action-pypi-publish@master
2021-04-20 08:09:31 +00:00
with:
2021-04-20 14:14:52 +00:00
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution package to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
2021-04-20 08:09:31 +00:00
with:
2021-04-20 14:14:52 +00:00
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}