Skip to content

Commit

Permalink
Add CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkbatya committed Jul 22, 2024
1 parent 05c410c commit 303bc49
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: 'Deploy'

on:
push:
branches:
- dev
tags:
- '*'
pull_request:

env:
IMAGE_NAME: "flipperdevices/github-actions-runner"

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: 'Checkout code'
uses: actions/checkout@v3

- name: 'Set image tag and name'
id: tag
run: |
IMAGE_TAG="0.0.0"
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
REF=${{ github.ref }};
TAG_FULL=${REF#refs/*/};
IMAGE_TAG=${TAG_FULL//\//_};
fi
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: 'Login to Docker Hub'
uses: docker/login-action@v2
with:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: 'Set up Docker Buildx'
uses: docker/setup-buildx-action@v3

- name: 'Build android'
uses: docker/build-push-action@v6
with:
push: false
tags: ${{ steps.tag.outputs.image_name }}-android:${{ steps.tag.outputs.image_tag }}
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}-android:buildcache
context: android

- name: 'Build flipperzero-firmware'
uses: docker/build-push-action@v6
with:
push: false
tags: ${{ steps.tag.outputs.image_name }}-fz-fw:${{ steps.tag.outputs.image_tag }}
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}-fz-fw:buildcache
context: flipperzero-firmware

- name: 'Push android'
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.tag.outputs.image_name }}-android:${{ steps.tag.outputs.image_tag }}
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}-android:buildcache
cache-to: type=registry,ref=${{ steps.tag.outputs.image_name }}-android:buildcache,mode=max
context: android

- name: 'Push flipperzero-firmware'
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.tag.outputs.image_name }}-fz-fw:${{ steps.tag.outputs.image_tag }}
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}-fz-fw:buildcache
cache-to: type=registry,ref=${{ steps.tag.outputs.image_name }}-fz-fw:buildcache,mode=max
context: flipperzero-firmware

- name: 'Trigger k8s to use new image android: prod'
if: ${{ (github.event_name != 'pull_request')
&& (steps.tag.outputs.image_tag != '0.0.0')
&& (!endsWith(github.event.client_payload.image_tag, '-rc')) }}
uses: peter-evans/repository-dispatch@v3
with:
repository: ${{ secrets.INFRASTRUCTURE_REPO }}
token: ${{ secrets.K8S_GITHUB_PAT }}
event-type: ${{ steps.tag.outputs.image_name }}-android-deploy
client-payload: '{"image_tag": "${{steps.tag.outputs.image_tag}}"}'

- name: 'Trigger k8s to use new image flipperzero-firmware: prod'
if: ${{ (github.event_name != 'pull_request')
&& (steps.tag.outputs.image_tag != '0.0.0')
&& (!endsWith(github.event.client_payload.image_tag, '-rc')) }}
uses: peter-evans/repository-dispatch@v3
with:
repository: ${{ secrets.INFRASTRUCTURE_REPO }}
token: ${{ secrets.K8S_GITHUB_PAT }}
event-type: ${{ steps.tag.outputs.image_name }}-fz-fw-deploy
client-payload: '{"image_tag": "${{steps.tag.outputs.image_tag}}"}'

0 comments on commit 303bc49

Please sign in to comment.