Skip to content

Commit

Permalink
chore(release): don't run jobs unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
evegufy committed Apr 4, 2024
1 parent d3494de commit 5d07bab
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
app-version: ${{ steps.app-version.outputs.current }}
version-check: ${{ steps.version-check.outputs.exists }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
Expand All @@ -60,8 +63,26 @@ jobs:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_SKIP_EXISTING: "true"

- name: Get current appVersion
id: app-version
run: |
current=$(cat ./charts/dim/Chart.yaml | grep "appVersion:" | head -1 | cut -d ":" -d " " -f2)
echo "current=$current" >> $GITHUB_OUTPUT
echo "Exported $current appVersion"
- name: Check for previous version
id: version-check
run: |
exists=$(git tag -l "v${{ steps.app-version.outputs.current }}")
if [[ -n "$exists" ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
release-images:
needs: release-helm-chart
if: needs.release-helm-chart.outputs.version-check == 'false'
permissions:
packages: write
runs-on: ubuntu-latest
Expand All @@ -74,47 +95,24 @@ jobs:
dockerfile: ./docker/Dockerfile-dim-migrations
- image: ghcr.io/${{ github.repository }}_dim-processes-worker
dockerfile: ./docker/Dockerfile-dim-processes-worker
outputs:
app-version: ${{ steps.app-version.outputs.current }}
version-check: ${{ steps.version-check.outputs.exists }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Get current appVersion
id: app-version
run: |
current=$(cat ./charts/dim/Chart.yaml | grep "appVersion:" | head -1 | cut -d ":" -d " " -f2)
echo "current=$current" >> $GITHUB_OUTPUT
echo "Exported $current appVersion"
- name: Check for previous version
id: version-check
run: |
exists=$(git tag -l "v${{ steps.app-version.outputs.current }}")
if [[ -n "$exists" ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Login to GitHub Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: steps.version-check.outputs.exists == 'false'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0
if: steps.version-check.outputs.exists == 'false'

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
if: steps.version-check.outputs.exists == 'false'

# Create SemVer or ref tags dependent of trigger event
- name: Docker meta
Expand All @@ -128,10 +126,9 @@ jobs:
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest
type=semver,pattern={{version}},value=${{ steps.app-version.outputs.current }}
type=semver,pattern={{major}},value=${{ steps.app-version.outputs.current }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.app-version.outputs.current }}
if: steps.version-check.outputs.exists == 'false'
type=semver,pattern={{version}},value=${{ needs.release-helm-chart.outputs.app-version }}
type=semver,pattern={{major}},value=${{ needs.release-helm-chart.outputs.app-version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-helm-chart.outputs.app-version }}
- name: Build and push Docker images
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
Expand All @@ -143,10 +140,10 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
if: steps.version-check.outputs.exists == 'false'

create-tag:
needs: release-images
if: needs.release-helm-chart.outputs.version-check == 'false'
permissions:
contents: write
runs-on: ubuntu-latest
Expand All @@ -158,6 +155,5 @@ jobs:

- name: Create and push git tag
run: |
git tag v${{ needs.release-images.outputs.app-version }}
git push origin v${{ needs.release-images.outputs.app-version }}
if: needs.release-images.outputs.version-check == 'false'
git tag v${{ needs.release-helm-chart.outputs.app-version }}
git push origin v${{ needs.release-helm-chart.outputs.app-version }}

0 comments on commit 5d07bab

Please sign in to comment.