Open Issue when monitored repos release a new version #5
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: Open Issue when monitored repos release a new version | |
on: | |
schedule: | |
- cron: 45 12 1 * * | |
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 | |
shell: bash | |
run: | | |
apt update -y | |
apt install -y curl jq wget | |
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 -y ./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 ytti/oxidized librenms/librenms' |