Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support github actions uses images #1

Merged
merged 1 commit into from
Dec 12, 2022
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
14 changes: 14 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
26 changes: 26 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Release

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/[email protected]
- 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/[email protected]
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_SECRETS }}
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

# github-action-workflow
GitHub Actions compatible workflows

## Usage

```shell
gaw convert .github/workflows/pull-request.yaml
```
3 changes: 3 additions & 0 deletions pkg/argo-workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/argo-workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions pkg/data/argo-workflows-image.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions pkg/data/github-action-image.yaml
Original file line number Diff line number Diff line change
@@ -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