Skip to content

Commit

Permalink
CI: only run when changes are made
Browse files Browse the repository at this point in the history
  • Loading branch information
anishshobithps committed Jan 11, 2025
1 parent 67a2255 commit 07c990f
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,34 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Check for Docker changes
id: docker-changes
- name: Check for relevant changes
id: changes
run: |
CHANGED=0
# Fetch the latest changes
git fetch origin main
if [ "$(git rev-list --count HEAD)" -gt 1 ]; then
# Ensure that there is more than 1 commit in the history
if git diff --name-only HEAD^ HEAD | grep -q "^\.docker/"; then
CHANGED=1
fi
else
# If there's no previous commit, assume no changes
CHANGED=0
# Check for changes in .tex, .sty, .cls, or Docker-related files
if git diff --name-only HEAD^ HEAD | grep -E "^(.docker/|.*\.(tex|sty|cls)$)" > /dev/null; then
CHANGED=1
fi
echo "changed=${CHANGED}" >> $GITHUB_OUTPUT
- name: Set up Docker
if: steps.docker-changes.outputs.changed == '1'
if: steps.changes.outputs.changed == '1'
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: steps.docker-changes.outputs.changed == '1'
if: steps.changes.outputs.changed == '1'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and cache Docker image
if: steps.docker-changes.outputs.changed == '1'
if: steps.changes.outputs.changed == '1'
uses: docker/build-push-action@v5
with:
context: .docker
Expand Down Expand Up @@ -76,7 +74,7 @@ jobs:
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Create Release
if: github.ref == 'refs/heads/main'
if: steps.changes.outputs.changed == '1' && github.ref == 'refs/heads/main'
uses: softprops/action-gh-release@v2
with:
draft: false
Expand Down

0 comments on commit 07c990f

Please sign in to comment.