diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml new file mode 100644 index 0000000..f676560 --- /dev/null +++ b/.github/workflows/cron.yml @@ -0,0 +1,54 @@ +name: Open Issue when monitored repos release a new version +on: + schedule: + - cron: 0,15,30,45 * * * * + +jobs: + create_issue: + name: Open Issue when monitored repos release a new version + runs-on: ubuntu-latest + container: + image: ubuntu:latest + permissions: + issues: write + steps: + - name: Open Issue when monitored repos release a new version + run: | + apt update -y + apt install -y curl jq + url=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | jq -r '.assets[].browser_download_url|select(contains("linux") and contains("amd64") and contains(".deb"))') + wget $url + apt install ./gh_*_linux_amd64.deb + rm gh_*_linux_amd64.deb + if ! gh --version; then + echo "GitHub CLI was not installed" + exit 1 + fi + for repo in $MONITORED_REPOS; do + project=$(echo $repo | cut -d '/' -f 2) + previous_issue_date=$(gh issue list \ + --repo $GH_REPO \ + --json createdAt \ + -s all \ + -S "[Chore]: Upgrade $project to" \ + -L 1 \ + --jq '.[0].createdAt' \ + | tr -d '"') + new_release=$(gh release list -R $repo \ + --exclude-drafts \ + --exclude-pre-releases \ + --json publishedAt,tagName \ + --jq '.[0]') + new_release_tag=$(echo $new_release | jq '.tagName' | tr -d '"') + new_release_date=$(echo $new_release | jq '.publishedAt' | tr -d '"') + if [[ "$previous_issue_date" < "$new_release_date" ]]; then + gh issue create \ + --repo $GH_REPO \ + --title "[Chore]: Upgrade $project to $new_release_tag" \ + --body "$(gh release view $new_release_tag --repo $repo --json body --jq '.body')" + fi + done + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + MONITORED_REPOS: 'netbox-community/netbox netbox-community/netbox-docker'