CI: move image building to GitHub actions (#335)

* Start working on building image in GitHub actions

* Trigger GitHub on push to any branch

* Fix TRAVIS_TAG

* Add compress image step

* Disable image build in Travis

* Add upload image step

* Fix compress image

* Fix

* Fix

* Minor fix

* Trigger build on tag

* Show images sizes not in human format

* Upload only built image

* Make prerelease

* Upload assets on release not on tags
This commit is contained in:
Oleg Kalachev
2021-05-28 01:25:29 +03:00
committed by GitHub
parent fad7886012
commit f4d07e2c2c
2 changed files with 63 additions and 42 deletions

View File

@@ -6,15 +6,36 @@ name: CI
on: on:
# Triggers the workflow on push or pull request events but only for the master branch # Triggers the workflow on push or pull request events but only for the master branch
push: push:
branches: [ master ] branches: [ '*' ]
pull_request: pull_request:
branches: [ master ] branches: [ master ]
release:
types: [ created ]
# Allows you to run this workflow manually from the Actions tab # Allows you to run this workflow manually from the Actions tab
workflow_dispatch: workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel # A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs: jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build image
run: |
docker run --privileged --rm -v /dev:/dev -v $(pwd):/builder/repo -e TRAVIS_TAG="${{ github.event.release.tag_name }}" sfalexrog/img-tool:qemu-update
- name: Compress image
run: |
sudo chmod -R 777 images && zip -9 $(echo images/clover_*).zip images/clover_* && ls -l images
- name: Upload image
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
files: images/clover_*.zip
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# This workflow contains a single job called "build" # This workflow contains a single job called "build"
build: build:
# The type of runner that the job will run on # The type of runner that the job will run on

View File

@@ -14,47 +14,47 @@ git:
jobs: jobs:
fast_finish: true fast_finish: true
include: include:
- stage: Build # - stage: Build
name: "Raspberry Pi Image Build" # name: "Raspberry Pi Image Build"
cache: # cache:
directories: # directories:
- imgcache # - imgcache
before_script: # before_script:
- if [ ! -z "$DOCKER_USERNAME" ]; then # - if [ ! -z "$DOCKER_USERNAME" ]; then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; # echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin;
fi # fi
- docker pull ${DOCKER} # - docker pull ${DOCKER}
# Check if there are any cached images, copy them to our "images" directory # # Check if there are any cached images, copy them to our "images" directory
- if [ -n "$(ls -A imgcache/*.zip)" ]; then mkdir -p images && cp imgcache/*.zip images; fi # - if [ -n "$(ls -A imgcache/*.zip)" ]; then mkdir -p images && cp imgcache/*.zip images; fi
script: # script:
- if [[ -z ${TRAVIS_TAG} && "${TRAVIS_PULL_REQUEST}" != "false" ]]; then # - if [[ -z ${TRAVIS_TAG} && "${TRAVIS_PULL_REQUEST}" != "false" ]]; then
echo "Commit range is ${TRAVIS_COMMIT_RANGE}" && # echo "Commit range is ${TRAVIS_COMMIT_RANGE}" &&
if [ $(git diff --name-only ${TRAVIS_COMMIT_RANGE} | grep -v ^"docs/" | wc -l) -eq 0 ]; then # if [ $(git diff --name-only ${TRAVIS_COMMIT_RANGE} | grep -v ^"docs/" | wc -l) -eq 0 ]; then
echo " === Docs-only change; skipping build ===" && # echo " === Docs-only change; skipping build ===" &&
export SKIP_BUILD=true; # export SKIP_BUILD=true;
fi; # fi;
fi # fi
- if [ -z ${SKIP_BUILD} ]; then # - if [ -z ${SKIP_BUILD} ]; then
docker run --privileged --rm -v /dev:/dev -v $(pwd):/builder/repo -e TRAVIS_TAG="${TRAVIS_TAG}" ${DOCKER}; # docker run --privileged --rm -v /dev:/dev -v $(pwd):/builder/repo -e TRAVIS_TAG="${TRAVIS_TAG}" ${DOCKER};
fi # fi
before_cache: # before_cache:
- cp images/*.zip imgcache # - cp images/*.zip imgcache
after_success: # after_success:
- sudo chmod -R 777 * # - sudo chmod -R 777 *
- cd images && zip -9 ${IMAGE_NAME}.zip ${IMAGE_NAME} && stat --printf="Compressed image size:%s\n" ${IMAGE_NAME}.zip # - cd images && zip -9 ${IMAGE_NAME}.zip ${IMAGE_NAME} && stat --printf="Compressed image size:%s\n" ${IMAGE_NAME}.zip
before_deploy: # before_deploy:
# Set up git user name and tag this commit # # Set up git user name and tag this commit
- git config --local user.name "goldarte" # - git config --local user.name "goldarte"
- git config --local user.email "goldartt@gmail.com" # - git config --local user.email "goldartt@gmail.com"
deploy: # deploy:
provider: releases # provider: releases
token: ${GITHUB_OAUTH_TOKEN} # token: ${GITHUB_OAUTH_TOKEN}
file: ${IMAGE_NAME}.zip # file: ${IMAGE_NAME}.zip
skip_cleanup: true # skip_cleanup: true
on: # on:
tags: true # tags: true
draft: true # draft: true
name: ${TRAVIS_TAG} # name: ${TRAVIS_TAG}
# - stage: Build # - stage: Build
# name: "Native Kinetic build" # name: "Native Kinetic build"
# env: # env: