Check for updates #983
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: Check for updates | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # Github recommends avoiding full hours | |
| # See https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule | |
| - cron: "38 1,9,17 * * *" # At minute 38 every 8 hours | |
| concurrency: | |
| group: auto-updates | |
| cancel-in-progress: false | |
| jobs: | |
| define-matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| packages: ${{ steps.nvcheck.outputs.packages }} | |
| changes: ${{ steps.nvcheck.outputs.changes }} | |
| urls: ${{ steps.nvcheck.outputs.urls }} | |
| new-versions: ${{ steps.nvcheck.outputs.new_versions }} | |
| new-versions-flaky: ${{ steps.nvcheck.outputs.new_versions_flaky }} | |
| steps: | |
| - name: Clone repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| ssh-key: ${{ secrets.SSH_KEY_PRIVATE }} | |
| - name: Pull Arch Linux image | |
| run: docker pull quay.io/aminvakil/archlinux:latest | |
| - name: Create keyfile | |
| run: | | |
| # Create keyfile to avoid Github rate limits | |
| # See https://nvchecker.readthedocs.io/en/latest/usage.html#configuration-table:~:text=toml%20config%20file%20containing%20key | |
| cat >> keyfile.toml<< EOF | |
| [keys] | |
| github = "${{ secrets.GITHUB_TOKEN }}" | |
| EOF | |
| - name: Prepare nvchecker | |
| run: | | |
| container_id=$(mktemp) | |
| docker run --detach --privileged --cgroup-parent=docker.slice --cgroupns private --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v "${PWD}":/pkgbuilds quay.io/aminvakil/archlinux:latest > "${container_id}" | |
| docker exec "$(cat ${container_id})" pacman -Syu --noconfirm | |
| docker exec "$(cat ${container_id})" pacman -S nvchecker git pyalpm python-packaging python-jq --noconfirm | |
| echo "container_id=$container_id" >> $GITHUB_ENV | |
| - name: Install yq | |
| run: | | |
| sudo apt-get -y install yq # needed for tomlq | |
| - name: Run nvchecker | |
| id: nvcheck | |
| run: | | |
| nvcmp_output='' | |
| for file in nvchecker{,_flaky}.toml; do | |
| failures='--failures' | |
| if [ "$file" == 'nvchecker_flaky.toml' ]; then | |
| failures='' | |
| fi | |
| docker exec "$(cat ${container_id})" nvchecker ${failures} -k /pkgbuilds/keyfile.toml -c /pkgbuilds/${file} | |
| out=$(docker exec "$(cat ${container_id})" nvcmp -c /pkgbuilds/${file} -j) | |
| if [ -z "$out" ] || [ "$out" == '[]' ]; then | |
| echo "::notice ::No new versions found in ${file}" | |
| fi | |
| nvcmp_output+=$out | |
| done | |
| # Merge outputs from the loop | |
| nvcmp_output=$(echo "$nvcmp_output" | jq -cs 'add') | |
| rm -f keyfile.toml # Only needed for the nvchecker command | |
| if [ -z "$nvcmp_output" ] || [ "$nvcmp_output" == '[]' ]; then | |
| echo "::notice ::No new versions found" | |
| fi | |
| pkgs=$(echo "$nvcmp_output" | jq -c '[.[].name]') | |
| echo "packages=$pkgs" >> $GITHUB_OUTPUT | |
| echo "changes=$nvcmp_output" >> $GITHUB_OUTPUT | |
| new_versions=$(cat versions_new.json | jq -c) | |
| echo "new_versions=$new_versions" >> $GITHUB_OUTPUT | |
| new_versions_flaky=$(cat versions_flaky_new.json | jq -c) | |
| echo "new_versions_flaky=$new_versions_flaky" >> $GITHUB_OUTPUT | |
| # Calculate release URLs | |
| urls='' | |
| pkgs=$(echo "$nvcmp_output" | jq -c '[.[].name]') | |
| while read -r pkg; do | |
| version=$(echo "$nvcmp_output" | jq -r '.[] | select(.name=="'${pkg}'").newver') | |
| expr=$(printf '."%s"' "$pkg") | |
| src=$(tomlq -r ${expr}.source nvchecker.toml) | |
| if [ -z "$src" ]; then | |
| src=$(tomlq -r ${expr}.source nvchecker_flaky.toml) | |
| fi | |
| url='' | |
| if [ "${src}" == "github" ]; then | |
| repo=$(tomlq -r ${expr}.github nvchecker.toml) | |
| pfx=$(tomlq -r ${expr}.prefix nvchecker.toml) | |
| if [ -z "$repo" ]; then | |
| repo=$(tomlq -r ${expr}.github nvchecker_flaky.toml) | |
| pfx=$(tomlq -r ${expr}.prefix nvchecker_flaky.toml) | |
| if [ "${pfx}" == "null" ]; then | |
| pfx="" | |
| fi | |
| fi | |
| url=$(printf "https://github.com/${repo}/releases/tag/${pfx}${version}") | |
| else | |
| url=$(tomlq -r ${expr}.release_url nvchecker.toml) | |
| if [ "$url" == 'null' ]; then | |
| url=$(tomlq -r ${expr}.url nvchecker.toml) | |
| fi | |
| if [ "$url" == 'null' ]; then | |
| url=$(tomlq -r ${expr}.release_url nvchecker_flaky.toml) | |
| fi | |
| if [ "$url" == 'null' ]; then | |
| url=$(tomlq -r ${expr}.url nvchecker_flaky.toml) | |
| fi | |
| url=$(echo "$url" | sed 's/__version__/'${version}'/g') | |
| fi | |
| if [ "$url" == 'null' ]; then | |
| url='None' | |
| fi | |
| urls+=$(echo "${pkg}=${url}" | jq -R './"=" | {key:first,value:last}') | |
| done <<< "$(echo $pkgs | jq -r '.[]')" | |
| urls=$(echo "$urls" | jq -cs 'from_entries') | |
| echo "urls=$urls" >> $GITHUB_OUTPUT | |
| - name: Stop nvchecker | |
| run: | | |
| docker rm -f "$(cat ${container_id})" | |
| create-prs: | |
| name: Create PR for ${{ matrix.package }} | |
| needs: define-matrix | |
| if: needs.define-matrix.outputs.packages != '[]' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJSON(needs.define-matrix.outputs.packages) }} | |
| steps: | |
| - name: Install yq | |
| run: | | |
| sudo apt-get -y install yq # needed for tomlq | |
| - name: Identify version and release URL | |
| id: identify | |
| run: | | |
| newver=$(echo '${{ needs.define-matrix.outputs.changes }}' | jq -r '.[] | select(.name=="${{ matrix.package }}").newver') | |
| url=$(echo '${{ needs.define-matrix.outputs.urls }}' | jq -r '."${{ matrix.package }}"') | |
| echo "pkgver=$newver" >> $GITHUB_OUTPUT | |
| # pkgrel reset with new pkgver | |
| echo "pkgrel=1" >> $GITHUB_OUTPUT | |
| echo "url=$url" >> $GITHUB_OUTPUT | |
| - name: Clone repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| ssh-key: ${{ secrets.SSH_KEY_PRIVATE }} | |
| - name: Prepare nvchecker | |
| run: | | |
| echo '${{ needs.define-matrix.outputs.new-versions }}' > versions_new.json | |
| echo '${{ needs.define-matrix.outputs.new-versions-flaky }}' > versions_flaky_new.json | |
| container_id=$(mktemp) | |
| docker run --detach --privileged --cgroup-parent=docker.slice --cgroupns private --tmpfs /tmp --tmpfs /run --tmpfs /run/lock -v "${PWD}":/pkgbuilds quay.io/aminvakil/archlinux:latest > "${container_id}" | |
| docker exec "$(cat ${container_id})" pacman -Syu --noconfirm | |
| docker exec "$(cat ${container_id})" pacman -S nvchecker --noconfirm | |
| echo "container_id=$container_id" >> $GITHUB_ENV | |
| - name: Prepare commit message | |
| uses: ./.github/actions/prepare-commit-msg | |
| id: prep | |
| with: | |
| pkgname: ${{ matrix.package }} | |
| new-pkgver: ${{ steps.identify.outputs.pkgver }} | |
| new-pkgrel: ${{ steps.identify.outputs.pkgrel }} | |
| skip-ci: ${{ matrix.package == 'firefox-vaapi' && 'yes' || 'no' }} | |
| - name: Update PKGBUILD and generate diff | |
| uses: ./.github/actions/updpkgsums | |
| id: update | |
| with: | |
| pkgname: ${{ matrix.package }} | |
| new-pkgver: ${{ steps.identify.outputs.pkgver }} | |
| new-pkgrel: ${{ steps.identify.outputs.pkgrel }} | |
| skip-makepkg: ${{ matrix.package == 'firefox-vaapi' && 'yes' || 'no' }} | |
| - name: Run nvtake | |
| run: | | |
| if [ $(tomlq -cr '."${{ matrix.package }}"' nvchecker.toml) != 'null' ]; then | |
| docker exec "$(cat ${container_id})" nvtake -c /pkgbuilds/nvchecker.toml ${{ matrix.package }} | |
| else | |
| docker exec "$(cat ${container_id})" nvtake -c /pkgbuilds/nvchecker_flaky.toml ${{ matrix.package }} | |
| fi | |
| - name: Configure git and SSH | |
| uses: ./.github/actions/configure-git-ssh | |
| id: configure | |
| with: | |
| ssh-priv-key: ${{ secrets.SSH_KEY_PRIVATE }} | |
| commit-email: ${{ secrets.GIT_EMAIL }} | |
| commit-user: ${{ secrets.GIT_USER }} | |
| - name: Create PR | |
| uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 | |
| id: pr | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: ${{ steps.prep.outputs.commit-msg }} | |
| committer: ${{ secrets.GIT_USER }} <${{ secrets.GIT_EMAIL }}> | |
| author: ${{ secrets.GIT_USER }} <${{ secrets.GIT_EMAIL }}> | |
| branch: aur/${{ matrix.package }} | |
| title: "Update ${{ matrix.package }} to ${{ steps.identify.outputs.pkgver }}" | |
| body: ${{ steps.identify.outputs.url }} | |
| delete-branch: true | |
| signoff: false | |
| draft: false | |
| - name: Warn if makepkg was skipped | |
| if: steps.update.outputs.built == 'no' | |
| uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 | |
| with: | |
| pr-number: ${{ steps.pr.outputs.pull-request-number }} | |
| message: | | |
| :rotating_light: **WARNING** :rotating_light: | |
| `makepkg` was not executed. Verify package locally before merging! | |
| - name: Stop nvchecker | |
| run: | | |
| docker rm -f "$(cat ${container_id})" |