Skip to content

Scheduled - Build and Push to ECR (prod) #5

Scheduled - Build and Push to ECR (prod)

Scheduled - Build and Push to ECR (prod) #5

on:
schedule:
- cron: '0 5 * * 3' # at 05:00 UTC every Wednesday
name: Scheduled - Build and Push to ECR (prod)
jobs:
# The workflow should work only in the first week of the month
check-first-week:
runs-on: ubuntu-latest
outputs:
is-first-week-of-month: ${{ steps.check-week.outputs.is-first-week }}
steps:
- name: Check if it's the first week of the month
id: check-week
run: |
if [ $(date +'%d' | sed 's/^0*//') -le 7 ]; then
echo "is-first-week=true" >> $GITHUB_OUTPUT
else
echo "is-first-week=false" >> $GITHUB_OUTPUT
fi
get-latest-tag:
needs: check-first-week
if: ${{ needs.check-first-week.outputs.is-first-week-of-month == 'true' }}
name: "Get latest tag"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Required due to the way Git works, without it this action won't be able to find any or the correct tags
fetch-depth: 0
- name: Get latest tag
id: get-latest-tag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
prefix: v
outputs:
latest-tag: ${{ steps.get-latest-tag.outputs.tag }}
build-and-push:
needs: get-latest-tag
name: (prod) Scheduled Build and Push
uses: ./.github/workflows/reusable-docker-publish.yaml
with:
environment: "prod"
ref: ${{ needs.get-latest-tag.outputs.latest-tag }}
secrets: inherit