Skip to content

Commit

Permalink
Automate update version list periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
yanecc committed Jun 30, 2024
1 parent 3289cf7 commit ea6ae4a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Binary file added .github/UpdateVersionList
Binary file not shown.
39 changes: 39 additions & 0 deletions .github/UpdateVersionList.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "http/client"
require "json"
require "option_parser"

def fetchVersionList
response = HTTP::Client.get "https://github.com/version-fox/vfox-clang/releases/manifest"
versionJson = response.body.match!(/<code>([\s\S]+)<\/code>/)[1]
versionList = Hash(String, Array(String)).from_json versionJson
end

output = "manifest.md"

OptionParser.parse do |parser|
parser.banner = "Usage: #{Path[Process.executable_path.not_nil!].stem} [options]"
parser.on("-o PATH", "--output PATH", "Specify the output path") { |path| output = path }
parser.on("-h", "--help", "Show this help") do
puts parser
exit
end
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end

vlist = fetchVersionList
resp = HTTP::Client.get "https://anaconda.org/conda-forge/clang/labels"
latestClangVersion = resp.body.match!(/\d\d\.\d\.\d/)[0]

if vlist["conda-forge"][0] != latestClangVersion
vlist["conda-forge"].unshift(latestClangVersion)
puts "Clang has an updated version: #{latestClangVersion}"
File.open(output, "a") do |file|
file.puts "```"
file.puts vlist.to_pretty_json(indent = " ")
file.puts "```"
end
end
40 changes: 40 additions & 0 deletions .github/workflows/Update version list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Check Updates Periodically

on:
schedule:
- cron: "0 16 * * 1,4"
push:
branches: ["main"]

jobs:
update-version-list:
runs-on: ubuntu-latest

steps:
- name: Download source
uses: actions/checkout@v4

- name: Check updates
id: check_updates
run: |
chmod +x ./.github/UpdateVersionList
./.github/UpdateVersionList -o manifest.md
if [ -s manifest.md ]; then
HAS_UPDATES=true
echo "Updates found"
else
HAS_UPDATES=false
echo "Already up to date"
fi
echo "HAS_UPDATES=$HAS_UPDATES" >> $GITHUB_OUTPUT
- name: Update manifest body
if: ${{ steps.check_updates.outputs.HAS_UPDATES == 'true' }}
uses: ncipollo/release-action@v1
with:
name: "manifest"
tag: "manifest"
allowUpdates: true
bodyFile: "manifest.md"
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true

0 comments on commit ea6ae4a

Please sign in to comment.