From f7cfee67985046f4894617ecd411d424249abb5e Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 12 Dec 2022 10:34:01 +0800 Subject: [PATCH] feat: support github actions uses images --- .github/workflows/release-drafter.yaml | 14 ++++++++++++ .github/workflows/release.yaml | 26 +++++++++++++++++++++ Makefile | 2 ++ README.md | 6 +++++ pkg/argo-workflow.go | 3 +++ pkg/argo-workflow_test.go | 4 ++++ pkg/data/argo-workflows-image.yaml | 31 ++++++++++++++++++++++++++ pkg/data/github-action-image.yaml | 11 +++++++++ 8 files changed, 97 insertions(+) create mode 100644 .github/workflows/release-drafter.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 pkg/data/argo-workflows-image.yaml create mode 100644 pkg/data/github-action-image.yaml diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..0320f51 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,14 @@ +name: Release Drafter + +on: + push: + branches: + - master + +jobs: + UpdateReleaseDraft: + runs-on: ubuntu-20.04 + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_SECRETS }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..d10838b --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,26 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + goreleaser: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3.0.0 + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2.9.1 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_SECRETS }} diff --git a/Makefile b/Makefile index 24c68f0..45f6742 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,5 @@ build: go build -o bin/gaw . copy: build cp bin/gaw /usr/local/bin +test-gh: + act -W pkg/data/ -j imageTest diff --git a/README.md b/README.md index 8a5e81e..85afd54 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,9 @@ # github-action-workflow GitHub Actions compatible workflows + +## Usage + +```shell +gaw convert .github/workflows/pull-request.yaml +``` diff --git a/pkg/argo-workflow.go b/pkg/argo-workflow.go index 4e10527..d86461a 100644 --- a/pkg/argo-workflow.go +++ b/pkg/argo-workflow.go @@ -35,6 +35,9 @@ func (w *Workflow) ConvertToArgoWorkflow() (output string, err error) { } else if strings.HasPrefix(w.Jobs[i].Steps[j].Uses, "goreleaser/goreleaser-action") { w.Jobs[i].Steps[j].Image = "goreleaser/goreleaser:v1.13.1" w.Jobs[i].Steps[j].Run = "goreleaser " + w.Jobs[i].Steps[j].With["args"] + } else if strings.HasPrefix(w.Jobs[i].Steps[j].Uses, "docker://") { + w.Jobs[i].Steps[j].Image = strings.TrimPrefix(w.Jobs[i].Steps[j].Uses, "docker://") + w.Jobs[i].Steps[j].Run = w.Jobs[i].Steps[j].With["args"] } else if w.Jobs[i].Steps[j].Uses != "" { // TODO not support yet, do nothing } else { diff --git a/pkg/argo-workflow_test.go b/pkg/argo-workflow_test.go index 70b44b6..b062b0a 100644 --- a/pkg/argo-workflow_test.go +++ b/pkg/argo-workflow_test.go @@ -17,6 +17,10 @@ func TestWorkflow_ConvertToArgoWorkflow(t *testing.T) { name: "simple", githubActions: "data/github-actions.yaml", argoWorkflows: "data/argo-workflows.yaml", + }, { + name: "with image", + githubActions: "data/github-action-image.yaml", + argoWorkflows: "data/argo-workflows-image.yaml", }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/pkg/data/argo-workflows-image.yaml b/pkg/data/argo-workflows-image.yaml new file mode 100644 index 0000000..24d1d4c --- /dev/null +++ b/pkg/data/argo-workflows-image.yaml @@ -0,0 +1,31 @@ +apiVersion: argoproj.io/v1alpha1 +kind: WorkflowTemplate +metadata: + name: imagetest +spec: + entrypoint: main + volumeClaimTemplates: + - metadata: + name: work + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 64Mi + + templates: + - name: main + dag: + tasks: + - name: test + template: test + - name: test + script: + image: alpine:3.8 + command: [sh] + source: | + echo 1 + volumeMounts: + - mountPath: /work + name: work + workingDir: /work \ No newline at end of file diff --git a/pkg/data/github-action-image.yaml b/pkg/data/github-action-image.yaml new file mode 100644 index 0000000..20eba86 --- /dev/null +++ b/pkg/data/github-action-image.yaml @@ -0,0 +1,11 @@ +name: imageTest + +jobs: + imageTest: + name: build + runs-on: ubuntu-20.04 + steps: + - name: test + uses: docker://alpine:3.8 + with: + args: echo 1