Check Repo Updates #179
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 Repo Updates | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * 0' # Check every Sunday | |
env: | |
IMAGES_DIR: "images" | |
jobs: | |
# Generate the values for the matrix where the updates are executed | |
generate-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.generate-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Generate Matrix Content | |
id: generate-matrix | |
run: | | |
IMAGES=$( ls -1 ${{ env.IMAGES_DIR }} | tr '\n' ',' | sed 's/[^,]\+/"\0"/g;s/,$//' ) | |
echo "matrix={ \"image\": [ ${IMAGES} ] }" >> $GITHUB_OUTPUT | |
# --- | |
# Update the version of the existing images when possible and launch pull request | |
check-repo-updates: | |
needs: generate-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{ fromJson( needs.generate-matrix.outputs.matrix ) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set env vars | |
run: | | |
echo "IMAGE_DIR=./images/${{ matrix.image }}" >> $GITHUB_ENV | |
- name: Update Current Tag | |
id: update_tag | |
run: | | |
cd ${{ env.IMAGE_DIR }} | |
echo "old-version=$( sed -n '/IMAGE_TAG/s/^.*=//p' image_info.sh || echo 'NOT_FOUND' )" >> $GITHUB_OUTPUT | |
[[ -f ./update_current_tag.sh ]] && ./update_current_tag.sh | |
echo "new-version=$( sed -n '/IMAGE_TAG/s/^.*=//p' image_info.sh || echo 'NOT_FOUND' )" >> $GITHUB_OUTPUT | |
continue-on-error: true | |
# Launch Pull Request only when the version is updated | |
- name: Create Pull Request for ${{ matrix.image }} | |
if: | |
${{ steps.update_tag.outputs.old-version != steps.update_tag.outputs.new-version }} | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.GRADIANT_BOT_TOKEN }} | |
base: main | |
body: | | |
This PR is auto-generated to automatically test and update version for image ${{ matrix.image }} | |
From -> ${{ matrix.image }}:${{ steps.update_tag.outputs.old-version }} | |
To -> ${{ matrix.image }}:${{ steps.update_tag.outputs.new-version }} | |
branch: ${{ matrix.image }}-version-update | |
commit-message: "Updating version ${{ matrix.image }} [${{ steps.update_tag.outputs.old-version }} -> ${{ steps.update_tag.outputs.new-version }}] " | |
delete-branch: true | |
title: "[${{ matrix.image }}] Update Version ${{ steps.update_tag.outputs.old-version }} -> ${{ steps.update_tag.outputs.new-version }}" | |
# --- |