Check for new releases and build Docker images #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for new releases and build Docker images | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Every day at midnight | |
workflow_dispatch: | |
env: | |
REGISTRY: imbios | |
PLATFORMS: linux/amd64,linux/arm64 | |
VERSIONS: 16,18,20 | |
TYPES: alpine,debian-slim,debian | |
jobs: | |
check-and-build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Check for new releases in nodejs/docker-node | |
id: nodejs | |
run: | | |
gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/nodejs/docker-node/releases/latest | jq -r '.tag_name' > latest_nodejs.txt | |
if [[ -f last_nodejs.txt && $(cat last_nodejs.txt) != $(cat latest_nodejs.txt) ]]; then | |
echo "New NodeJS version found." | |
echo "new-release=true" >> $GITHUB_ENV | |
cat latest_nodejs.txt > last_nodejs.txt | |
else | |
echo "new-release=false" >> $GITHUB_ENV | |
cat latest_nodejs.txt > last_nodejs.txt | |
fi | |
echo "nodejs-new-release=${{ env.new-release }}" >> $GITHUB_ENV | |
- name: Check for new releases in oven-sh/bun | |
id: bun | |
if: env.nodejs-new-release == 'true' | |
run: | | |
curl -s https://api.github.com/repos/oven-sh/bun/releases/latest | jq -r '.tag_name' > latest_bun.txt | |
if [[ -f last_bun.txt && $(cat last_bun.txt) != $(cat latest_bun.txt) ]]; then | |
echo "New Bun version found." | |
echo "new-release=true" >> $GITHUB_ENV | |
cat latest_bun.txt > last_bun.txt | |
else | |
echo "new-release=false" >> $GITHUB_ENV | |
cat latest_bun.txt > last_bun.txt | |
fi | |
echo "bun-new-release=${{ env.new-release }}" >> $GITHUB_ENV | |
- name: Determine if any new releases | |
if: env.nodejs-new-release == 'true' || env.bun-new-release == 'true' | |
run: echo "any-new-release=$(if [[ '${{ env.nodejs-new-release }}' == 'true' || '${{ env.bun-new-release }}' == 'true' ]]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_ENV | |
# Cache versions regardless of whether a new release is found | |
- name: Cache versions | |
id: cache-versions | |
if: env.any-new-release == 'true' | |
uses: actions/cache@v3 | |
with: | |
path: ./last_versions.json | |
key: ${{ runner.os }}-last_versions | |
- name: Setup Docker Buildx | |
if: env.any-new-release == 'true' | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
if: env.any-new-release == 'true' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker images | |
if: env.any-new-release == 'true' | |
run: ./build-all.sh | |
env: | |
REGISTRY: ${{ env.REGISTRY }} | |
PLATFORMS: ${{ env.PLATFORMS }} | |
VERSIONS: ${{ env.VERSIONS }} | |
TYPES: ${{ env.TYPES }} |