Skip to content

Commit

Permalink
ci: rework conditions for release and prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Oct 25, 2024
1 parent 31c92c9 commit e3c9131
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ name: Publish to GHCR

on:
workflow_call:
inputs:
release:
description: "Trigger a release build"
required: false
default: false
type: boolean
workflow_dispatch:

env:
Expand Down Expand Up @@ -39,6 +45,12 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=${{ inputs.release }}
tags: |
type=raw,value=latest,enable=${{ inputs.release }}
type=ref,event=tag
type=sha
- name: Build and push Docker image
id: push
Expand Down
25 changes: 24 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release new version
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- '**'

permissions:
contents: write
Expand Down Expand Up @@ -105,10 +105,22 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
release: ${{ steps.set-release.outputs.release }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set release variable
id: set-release
run: |
mainCount=$(git branch -r --contains ${{ github.ref }} --format "%(refname:lstrip=3)" | grep -xc main)
if [[ $GITHUB_REF =~ ^refs/tags/[0-9]+.[0-9]+.[0-9]+$ && $mainCount -gt 0 ]]; then
echo "release=true" >> $GITHUB_ENV
else
echo "release=false" >> $GITHUB_ENV
fi
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -119,6 +131,7 @@ jobs:
working-directory: artifacts

- name: Create release
if: ${{ steps.set-release.outputs.release == 'true' }}
run: |-
gh release create --generate-notes \
${{ github.ref_name }} \
Expand All @@ -127,9 +140,19 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}

- name: Create pre-release
if: ${{ steps.set-release.outputs.release == 'false' }}
run: |-
gh release create --generate-notes --prerelease \
${{ github.ref_name }} \
versions.json \
artifacts/*/datadog-static-analyzer*.zip
ghcr:
needs: release
uses: './.github/workflows/ghcr.yml'
with:
release: ${{ needs.release.outputs.release }}
permissions:
contents: read
packages: write
Expand Down

0 comments on commit e3c9131

Please sign in to comment.