Skip to content

Commit

Permalink
Update ci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferret-san committed Nov 6, 2024
1 parent ae06140 commit 458bfbd
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ env:

on:
push:
branches: [celestia-develop]
branches:
- main
- develop
- test/github-actions
pull_request:
branches: [celestia-develop]
branches:
- main
- develop
types: [opened, synchronize, reopened]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -46,37 +52,23 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare Docker Tags
id: prep
shell: bash
run: |
# Get short SHA
SHA="$(git rev-parse --short HEAD)"
# Sanitize branch name using parameter expansion
BRANCH="${GITHUB_REF#refs/heads/}"
BRANCH="${BRANCH//[^a-zA-Z0-9._-]/-}"
# For pull requests, use PR number
if [[ "${GITHUB_REF}" == refs/pull/* ]]; then
PR_NUMBER="$(echo "${GITHUB_REF}" | cut -d / -f 3)"
TAGS="${REGISTRY}/${REPO}/${{ matrix.component }}:pr-${PR_NUMBER}"
else
TAGS="${REGISTRY}/${REPO}/${{ matrix.component }}:${SHA}"
# Add branch tag if not a PR
if [ -n "${BRANCH}" ]; then
TAGS="${TAGS},${REGISTRY}/${REPO}/${{ matrix.component }}:${BRANCH}"
fi
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Generate Docker Tags
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.REPO }}/${{ matrix.component }}
tags: |
type=sha,format=short
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -85,12 +77,13 @@ jobs:
if: github.event_name == 'pull_request'
shell: bash
run: |
FIRST_TAG="$(echo "${{ steps.prep.outputs.tags }}" | cut -d',' -f1)"
# Get the first tag from metadata output
FIRST_TAG=$(echo '${{ steps.meta.outputs.tags }}' | head -n 1)
docker save "${FIRST_TAG}" > "/tmp/${{ matrix.component }}.tar"
- name: Upload Docker image
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: docker-${{ matrix.component }}
path: /tmp/${{ matrix.component celestia-
path: /tmp/${{ matrix.component }}.tar

0 comments on commit 458bfbd

Please sign in to comment.