diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c987e7608bc65..791bbf10c81cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 @@ -85,7 +77,8 @@ 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 @@ -93,4 +86,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: docker-${{ matrix.component }} - path: /tmp/${{ matrix.component celestia- + path: /tmp/${{ matrix.component }}.tar