Skip to content

Commit

Permalink
added pipeline for dispatch
Browse files Browse the repository at this point in the history
Signed-off-by: Dipankar Das <[email protected]>
  • Loading branch information
dipankardas011 committed Jun 14, 2024
1 parent 4652840 commit e8d4d09
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/falco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Get and Update Latest Releases

on:
workflow_dispatch:
workflow_call:

jobs:
TBD:
runs-on: ubuntu-latest
26 changes: 25 additions & 1 deletion .github/workflows/get-latest-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ concurrency:
jobs:
get-latest-version:
runs-on: ubuntu-latest

outputs:
is-falco-updated: ${{ steps.check-updates.outputs.FALCO }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand All @@ -30,3 +31,26 @@ jobs:
run: |
go run repo-variable-writer.go
- name: Dispatch
id: check-updates
env:
file: /tmp/updates.json # generated by go program
run: |
if jq -e --arg val "falco" '.proj_names | index($val) != null' "$file" > /dev/null; then
echo "Element '$value' found in the proj_names array."
echo "FALCO=true" >> $GITHUB_OUTPUT
else
echo "Element 'falco' not found in the proj_names array."
echo "FALCO=false" >> $GITHUB_OUTPUT
fi
falco-proj:
uses: ./.github/workflows/falco.yaml
if: ${{ needs.check-updates.outputs.is-falco-updated }} == 'true'
secrets: inherit
with:
image_tag: ${{ var.FALCO_VERSION }} # need to check if it gets the updated value
# permissions:
# packages: write
# contents: read
29 changes: 22 additions & 7 deletions scripts/repo-variable-writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type Projects struct {
}

const (
LocProjMeta string = "../projects/project.json"
LocProjMeta string = "../projects/project.json"
LocWriteUpdatedProjects string = "/tmp/updates.json"
)

func toPtr[T any](v T) *T {
Expand Down Expand Up @@ -122,7 +123,7 @@ func (obj *GithubVariable) genUrlAndHeaders(proj string) (*string, map[string]st
}, nil
}

func (obj *GithubVariable) Write(proj, value string) error {
func (obj *GithubVariable) Update(proj, value string) error {
url, header, err := obj.genUrlAndHeaders(proj)
if err != nil {
return err
Expand Down Expand Up @@ -196,7 +197,14 @@ func (obj *GithubVariable) Read(proj string) (*string, error) {
return toPtr[string](variableData.VariableValue), nil
}

func handleProjectsUpdater() {
func main() {

type UpdatedProjects struct {
ProjNames []string `json:"proj_names"`
}

updatedProjects := UpdatedProjects{}

projects, err := loadProjectMetadata(LocProjMeta)
if err != nil {
slog.Error("Failed: unable to read the projects Metadata", "Reason", err)
Expand Down Expand Up @@ -237,10 +245,11 @@ func handleProjectsUpdater() {

if strings.Compare(*storedRelease, *latestRelease) != 0 {
slog.Info("Release Versions", "Proj", proj.Name, "Org", proj.Organization, "Latest", *latestRelease, "Current", *storedRelease)
if err := storage.Write(proj.Name, *latestRelease); err != nil {
if err := storage.Update(proj.Name, *latestRelease); err != nil {
errChan <- err
return
}
updatedProjects.ProjNames = append(updatedProjects.ProjNames, proj.Name)
slog.Info("Updated to Latest version", "Proj", proj.Name, "Org", proj.Organization, "Ver", *latestRelease)

} else {
Expand All @@ -262,8 +271,14 @@ func handleProjectsUpdater() {
if hadFailures {
os.Exit(1)
}
}

func main() {
handleProjectsUpdater()
if v, err := json.Marshal(updatedProjects); err != nil {
slog.Error("failed to serialize the updated projects list", "Reason", err)
os.Exit(1)
} else {
if err := os.WriteFile(LocWriteUpdatedProjects, v, 0400); err != nil {
slog.Error("Failed to write the updated projects to a file", "Reason", err)
os.Exit(1)
}
}
}

0 comments on commit e8d4d09

Please sign in to comment.