Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Set the Auto-Collector to be triggered periodically #90

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/auto-submit-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:
branches:
- main
schedule:
- cron: '0 2 * * *'

name: auto-collector
jobs:
auto-createPR:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Launch auto-collector periodically
run: make collect
- name: Run read-yaml action
id: yaml-data
uses: CumulusDS/[email protected]
with:
file: ./EdgeXConfig/manifest.yaml
updated: updated
- name: Display read-yaml output
run: |
echo "${{ steps.yaml-data.outputs.updated }}"

- name: Create Pull Request
if: ${{ steps.yaml-data.outputs.updated == 'true' }}
uses: peter-evans/create-pull-request@v3
with:
commit-message: discover edgex new version
title: "[auto-collector] Discover edgex new version"
body: >
This PR is auto-generated by github action,please check and merge the config file in time.
labels: auto-collector, automated pr
branch: auto-collector-generated-branch
8 changes: 8 additions & 0 deletions EdgeXConfig/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
updated: "false"
count: 4
latestVersion: kamakura
versions:
- jakarta
- kamakura
- ireland
- hanoi
1 change: 0 additions & 1 deletion tools/collector/config/multiarch_imagelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ emqx/kuiper:1.1.1-alpine
postgres:12.3-alpine
vault:1.5.3
kong:2.0.5
kong:2.0.5
redis:6.0.9-alpine
26 changes: 26 additions & 0 deletions tools/collector/edgex/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,29 @@ func ModifyImagesName(edgexConfig *EdgeXConfig, repo string) {
}

}

func CollectVersionToManifest(versionList []*Version, oldManifest *Manifest) *Manifest {
versions := make([]string, 0)
for _, v := range versionList {
versions = append(versions, v.Name)
}
manifest := NewManifest()

for _, version := range versions {
manifest.Versions = append(manifest.Versions, version)
if !stringIsInArray(version, oldManifest.Versions) {
manifest.LatestVersion = version
}
}
if manifest.LatestVersion == "" {
manifest.LatestVersion = oldManifest.LatestVersion
}

manifest.Count = len(manifest.Versions)
if oldManifest.Count < len(manifest.Versions) {
manifest.Updated = "true"
} else {
manifest.Updated = "false"
}
return manifest
}
18 changes: 18 additions & 0 deletions tools/collector/edgex/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edgex

type Manifest struct {
Updated string `yaml:"updated"`
Count int `yaml:"count"`
LatestVersion string `yaml:"latestVersion"`
Versions []string `yaml:"versions"`
}

func NewManifest() *Manifest {
manifest := &Manifest{
Updated: "false",
Count: 0,
LatestVersion: "",
Versions: make([]string, 0),
}
return manifest
}
36 changes: 34 additions & 2 deletions tools/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package main

import (
"flag"
"io/ioutil"

"github.com/openyurtio/yurt-edgex-manager/tools/collector/edgex"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
)

var (
Expand All @@ -34,6 +34,7 @@ var (
repo string
amdArch = "amd"
armArch = "arm"
manifestPath = "../../EdgeXConfig/manifest.yaml"
)

func main() {
Expand Down Expand Up @@ -82,6 +83,21 @@ func Run() error {

edgex.ModifyImagesName(edgeXConfigAmd, repo)

var oldManifest edgex.Manifest

if _, err := os.Stat(manifestPath); err == nil {
//file is exist
manifestFile, err := ioutil.ReadFile(manifestPath)
err = yaml.Unmarshal(manifestFile, &oldManifest)
if err != nil {
return err
}
} else {
oldManifest = *edgex.NewManifest()
}

manifest := edgex.CollectVersionToManifest(edgeXConfigAmd.Versions, &oldManifest)

data, err := yaml.Marshal(edgeXConfigAmd)
if err != nil {
logger.Errorln("Fail to parse edgex config to yaml:", err)
Expand All @@ -104,6 +120,22 @@ func Run() error {

edgex.ModifyImagesName(edgeXConfigAmd, repo)

if manifest.Updated == "false" {
manifest = edgex.CollectVersionToManifest(edgeXConfigAmd.Versions, &oldManifest)
}

//write in the file
manifestData, err := yaml.Marshal(manifest)
if err != nil {
logger.Errorln("Fail to parse manifest config to yaml:", err)
return err
}
err = ioutil.WriteFile(manifestPath, manifestData, 0644)
if err != nil {
logger.Errorln("Fail to write manifest yaml:", err)
return err
}

data, err = yaml.Marshal(edgeXConfigAmd)
if err != nil {
logger.Errorln("Fail to parse edgex-nosecty config to yaml:", err)
Expand Down