Skip to content

container-toolkit Check #1327

container-toolkit Check

container-toolkit Check #1327

name: container-toolkit Check
on:
# Set schedule to run every 6 hours
schedule:
- cron: '0 */6 * * *'
# Allow to trigger action manually
workflow_dispatch:
jobs:
check_and_release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Check versions
run: |
# Grab latest nvidia-container-toolkit release from official repostiory and latest compiled release version from this repostiory
LATEST_TOOLKIT="$(curl -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -s https://api.github.com/repos/NVIDIA/nvidia-container-toolkit/releases/latest | jq -r '.tag_name' | sed 's/^v//')"
CURRENT_TOOLKIT="$(curl -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -s https://api.github.com/repos/unraid/nvidia-container-toolkit/releases/latest | jq -r '.tag_name' | sed 's/^v//')"
# Check if one of the versions is empty
if ! echo "${LATEST_TOOLKIT}" | grep -qE '^\b[0-9]+(\.[0-9]+)*\b$'; then
echo "Can't get versions"
exit 1
fi
if ! echo "${CURRENT_TOOLKIT}" | grep -qE '^\b[0-9]+(\.[0-9]+)*\b$'; then
echo "Can't get versions"
exit 1
fi
# Check versions
if [ "${LATEST_TOOLKIT}" != "${CURRENT_TOOLKIT}" ]; then
echo "CREATE_RELEASE=true" >> $GITHUB_ENV
echo "TOOLKIT_VERSION=${LATEST_TOOLKIT}" >> $GITHUB_ENV
else
echo "nvidia-container-toolkit v${CURRENT_TOOLKIT} up to date!"
echo "CREATE_RELEASE=false" >> $GITHUB_ENV
fi
- name: Log in to GitHub Container Registry
if: env.CREATE_RELEASE == 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run Docker container and build nvidia-container-toolkit
if: env.CREATE_RELEASE == 'true'
run: |
docker run --rm \
-v ${{ github.workspace }}/output:/tmp \
-e TOOLKIT_VERSION=${TOOLKIT_VERSION} \
ghcr.io/unraid/nvidia-container-toolkit:buster
- name: Create Release
if: env.CREATE_RELEASE == 'true' && success()
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TOOLKIT_VERSION }}
release_name: "nvidia-container-toolkit v${{ env.TOOLKIT_VERSION }}"
body: |
nvidia-container-toolkit v${{ env.TOOLKIT_VERSION }} for Unraid
draft: false
prerelease: false
- name: Upload tar.gz to Release
if: env.CREATE_RELEASE == 'true' && success()
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./output/v${{ env.TOOLKIT_VERSION }}/nvidia-container-toolkit-v${{ env.TOOLKIT_VERSION }}.tar.gz
asset_name: nvidia-container-toolkit-v${{ env.TOOLKIT_VERSION }}.tar.gz
asset_content_type: application/gzip
- name: Make a dummy commit
if: env.CREATE_RELEASE == 'false' && success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit --allow-empty -m "Keep GH Action alive"
git push