Fix CI #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
pull_request: | |
env: | |
IMAGE_NAME: "ghcr.io/flipperdevices/welcomer-bot" | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
if: ${{ !github.event.pull_request.head.repo.fork }} | |
steps: | |
- name: 'Checkout code' | |
uses: actions/checkout@v4 | |
- 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@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.REGISTRY_USER }} | |
password: ${{ secrets.REGISTRY_PASSWORD }} | |
- name: 'Set up Docker Buildx' | |
uses: docker/setup-buildx-action@v3 | |
- name: 'Build' | |
uses: docker/build-push-action@v5 | |
with: | |
push: false | |
tags: ${{steps.tag.outputs.image_name}}:${{steps.tag.outputs.image_tag}} | |
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache | |
- name: 'Push' | |
if: ${{ github.event_name != 'pull_request' }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ steps.tag.outputs.image_name }}:${{ steps.tag.outputs.image_tag }} | |
cache-from: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache | |
cache-to: type=registry,ref=${{ steps.tag.outputs.image_name }}:buildcache,mode=max | |
- name: 'Trigger k8s to use new image' | |
if: ${{ (github.event_name != 'pull_request') | |
&& (steps.tag.outputs.image_tag != '0.0.0') | |
&& (!endsWith(steps.tag.outputs.image_tag, '-rc')) }} | |
uses: peter-evans/repository-dispatch@v2 | |
with: | |
repository: ${{ secrets.INFRASTRUCTURE_REPO }} | |
token: ${{ secrets.K8S_GITHUB_PAT }} | |
event-type: welcomer-bot-deploy | |
client-payload: '{"image_tag": "${{steps.tag.outputs.image_tag}}"}' |