libnvidia-container Check #960
This file contains hidden or 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: libnvidia-container 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 libnvidia-container versions | |
| run: | | |
| # Grab latest libnvidia-container release from official repostiory and latest compiled release version from this repostiory | |
| LATEST_LIBNVIDIA="$(curl -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -s https://api.github.com/repos/NVIDIA/libnvidia-container/releases/latest | jq -r '.tag_name' | sed 's/^v//')" | |
| CURRENT_LIBNVIDIA="$(curl -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} -s https://api.github.com/repos/unraid/libnvidia-container/releases/latest | jq -r '.tag_name' | sed 's/^v//')" | |
| # Check if one of the versions is empty | |
| if ! echo "${LATEST_LIBNVIDIA}" | grep -qE '^\b[0-9]+(\.[0-9]+)*\b$'; then | |
| echo "Can't get versions" | |
| exit 1 | |
| fi | |
| if ! echo "${CURRENT_LIBNVIDIA}" | grep -qE '^\b[0-9]+(\.[0-9]+)*\b$'; then | |
| echo "Can't get versions" | |
| exit 1 | |
| fi | |
| # Check versions | |
| if [ "${LATEST_LIBNVIDIA}" != "${CURRENT_LIBNVIDIA}" ]; then | |
| echo "CREATE_RELEASE=true" >> $GITHUB_ENV | |
| echo "LIBNVIDIA_VERSION=${LATEST_LIBNVIDIA}" >> $GITHUB_ENV | |
| else | |
| echo "libnvidia-container v${CURRENT_LIBNVIDIA} up to date, skipping build!" | |
| 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 libnvidia-container | |
| if: env.CREATE_RELEASE == 'true' | |
| run: | | |
| docker run --rm \ | |
| -v ${{ github.workspace }}/output:/tmp \ | |
| -e LIBNVIDIA_VERSION=${LIBNVIDIA_VERSION} \ | |
| ghcr.io/unraid/libnvidia-container: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.LIBNVIDIA_VERSION }} | |
| release_name: "libnvidia-container v${{ env.LIBNVIDIA_VERSION }}" | |
| body: | | |
| libnvidia-container v${{ env.LIBNVIDIA_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.LIBNVIDIA_VERSION }}/libnvidia-container-v${{ env.LIBNVIDIA_VERSION }}.tar.gz | |
| asset_name: libnvidia-container-v${{ env.LIBNVIDIA_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 |