diff --git a/.github/workflows/auto-submit-pr.yaml b/.github/workflows/auto-submit-pr.yaml new file mode 100644 index 0000000..52832ae --- /dev/null +++ b/.github/workflows/auto-submit-pr.yaml @@ -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/get-yaml-paths-action@v1.0.1 + 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 \ No newline at end of file diff --git a/EdgeXConfig/manifest.yaml b/EdgeXConfig/manifest.yaml new file mode 100644 index 0000000..aa556fb --- /dev/null +++ b/EdgeXConfig/manifest.yaml @@ -0,0 +1,8 @@ +updated: "false" +count: 4 +latestVersion: kamakura +versions: + - jakarta + - kamakura + - ireland + - hanoi diff --git a/tools/collector/config/multiarch_imagelist.txt b/tools/collector/config/multiarch_imagelist.txt index ca29934..8a9acbb 100644 --- a/tools/collector/config/multiarch_imagelist.txt +++ b/tools/collector/config/multiarch_imagelist.txt @@ -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 diff --git a/tools/collector/edgex/collect.go b/tools/collector/edgex/collect.go index da2e9d0..6460670 100644 --- a/tools/collector/edgex/collect.go +++ b/tools/collector/edgex/collect.go @@ -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 +} diff --git a/tools/collector/edgex/def.go b/tools/collector/edgex/error.go similarity index 100% rename from tools/collector/edgex/def.go rename to tools/collector/edgex/error.go diff --git a/tools/collector/edgex/manifest.go b/tools/collector/edgex/manifest.go new file mode 100644 index 0000000..9fc6eb0 --- /dev/null +++ b/tools/collector/edgex/manifest.go @@ -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 +} diff --git a/tools/collector/main.go b/tools/collector/main.go index 24bdf59..d02b5ad 100644 --- a/tools/collector/main.go +++ b/tools/collector/main.go @@ -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 ( @@ -34,6 +34,7 @@ var ( repo string amdArch = "amd" armArch = "arm" + manifestPath = "../../EdgeXConfig/manifest.yaml" ) func main() { @@ -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) @@ -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)