netbox-docker/.github/workflows/check_changes.yml

97 lines
3.2 KiB
YAML
Raw Normal View History

2022-02-10 14:13:50 +01:00
name: Check Changes
on:
schedule:
# 07:00 UTC each day
- cron: '0 7 * * *'
2022-02-11 14:06:41 +01:00
push:
tags: ['*']
2022-02-10 14:13:50 +01:00
workflow_dispatch:
jobs:
2022-02-11 14:06:41 +01:00
get_tags:
2022-02-10 14:13:50 +01:00
runs-on: ubuntu-latest
outputs:
2022-02-11 14:06:41 +01:00
tags: ${{ steps.get.outputs.result }}
empty_tags: ${{ steps.check.outputs.result }}
2022-02-10 14:13:50 +01:00
steps:
2022-02-11 14:06:41 +01:00
- name: Docker target tags
id: fetch_target_tags
uses: mxpicture/action-docker-hub-fetch-tags@v1
2022-02-10 14:13:50 +01:00
with:
repository: mxpicture/openwrt-rootfs
max_items: "999999"
2022-02-11 14:06:41 +01:00
- name: Docker source tags
id: fetch_source_tags
uses: mxpicture/action-docker-hub-fetch-tags@v1
2022-02-10 14:13:50 +01:00
with:
repository: openwrtorg/rootfs
max_items: "999999"
2022-02-11 14:06:41 +01:00
- name: Get tags, compare docker hub image dates
2022-02-10 14:13:50 +01:00
uses: actions/github-script@v5
id: get
with:
script: |
2022-02-11 14:06:41 +01:00
const tags = (await github.request("https://api.github.com/repos/"
+ context.repo.owner + "/" + context.repo.repo + "/tags")).data
const target_tags = ${{ steps.fetch_target_tags.outputs.results }}
const source_tags = ${{ steps.fetch_source_tags.outputs.results }}
2022-02-10 14:13:50 +01:00
let output = []
2022-02-11 14:06:41 +01:00
for (const tag of tags) {
console.log("Processing tag: " + tag.name)
for (const source_tag of source_tags) {
if ( source_tag.name === tag.name ) {
2022-02-10 14:13:50 +01:00
let found = false
2022-02-11 14:06:41 +01:00
for (const target_tag of target_tags) {
if ( source_tag.name === target_tag.name ) {
2022-02-10 14:13:50 +01:00
found = true
2022-02-11 14:06:41 +01:00
console.log("Last updated (source): " + source_tag.last_updated)
console.log("Last updated (target): " + target_tag.last_updated)
if ( source_tag.last_updated > target_tag.last_updated ) {
console.log("Trigger event for tag: " + tag.name)
output.push({ "name": tag.name })
2022-02-10 14:13:50 +01:00
}
}
}
if (found != true) {
2022-02-11 14:06:41 +01:00
console.log("Trigger event for tag: " + tag.name)
output.push({ "name": tag.name })
2022-02-10 14:13:50 +01:00
}
}
}
}
return output
2022-02-11 14:06:41 +01:00
- name: Check tags empty
2022-02-10 14:13:50 +01:00
uses: actions/github-script@v5
id: check
with:
script: |
let output = ${{ steps.get.outputs.result }}
2022-02-11 14:06:41 +01:00
console.log("Count tags: " + (output.length))
2022-02-10 14:13:50 +01:00
if (output.length == 0) {
console.log("empty")
return 'true'
} else {
console.log("not empty")
return 'false'
}
dispatch:
2022-02-11 14:06:41 +01:00
needs: get_tags
if: ${{ fromJSON(needs.get_tags.outputs.empty_tags) == 'false' }}
2022-02-10 14:13:50 +01:00
runs-on: ubuntu-latest
strategy:
matrix:
2022-02-11 14:06:41 +01:00
tag: ${{ fromJSON(needs.get_tags.outputs.tags) }}
2022-02-10 14:13:50 +01:00
steps:
- name: Dispatch deploy
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.ACCESS_TOKEN }}
repository: ${{ github.repository }}
event-type: docker_hub
2022-02-11 14:06:41 +01:00
client-payload: '{"tag": "${{ matrix.tag.name }}"}'