Skip to content

Commit

Permalink
feat: add CI workflows for linting, testing, and Docker image build a…
Browse files Browse the repository at this point in the history
…nd push
  • Loading branch information
SkySingh04 committed Dec 30, 2024
1 parent 665f5de commit 4ba4797
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Lint Test Build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
name: Linting
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2
golangci-lint version
- name: Run golangci-lint
run: golangci-lint run --timeout=5m

test:
name: Testing
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- name: Install dependencies
run: go mod tidy

- name: Run tests
run: go test ./... -v

build:
name: Building
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21

- name: Install dependencies
run: go mod tidy

- name: Build the project
run: go build -o gocrab main.go

- name: Verify binary exists
run: |
if [ ! -f "./gocrab" ]; then
echo "Build failed: binary not found."
exit 1
fi
34 changes: 34 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Docker Build and Push

on:
workflow_run:
workflows:
- Lint Test Build
types:
- completed
jobs:
docker:
name: Build and Push to Docker Hub
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/gocrab:latest
${{ secrets.DOCKER_USERNAME }}/gocrab:${{ github.sha }}
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ git push origin feature/amazing-feature

Go to the original repository and create a Pull Request. Include a description of your changes, the reason behind them, and any additional context that may help the maintainers review your contribution.

#### Docker Image
If you're actively contributing to **GoCrab** and want to build and test the Docker image locally, use the following commands:

1. **Build the Docker Image**:
```sh
docker build -t gocrab .
```

2. **Run the Local Docker Image**:
```sh
docker run --rm -v $(pwd):/app gocrab /app/path/to/rust/file.rs
```

With Docker, **GoCrab** provides a simple and portable way to transpile Rust to Go without needing to install Go locally.


## Code of Conduct

Please note that GoCrab follows a Code of Conduct to foster an open and welcoming environment. By participating, you are expected to uphold this standard.
Expand Down
30 changes: 30 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,36 @@ GoCrab path/to/rust/file.rs

This command will generate a `.go` file with equivalent Go code in the same directory.

### Usage (Docker)

If you prefer to use Docker to run **GoCrab**, you can pull the latest image from Docker Hub and use it to transpile Rust code to Go.

#### Pull the Docker Image
To get the latest **GoCrab** image from Docker Hub, run the following command:

```sh
docker pull SkySingh04/gocrab:latest
```

#### Run the Transpiler
You can use the Docker container to transpile your Rust files. Mount the directory containing your Rust file and specify the file as an argument:

```sh
docker run --rm -v $(pwd):/app SkySingh04/gocrab:latest /app/path/to/rust/file.rs
```

This will generate the transpiled `.go` file in the same directory as your Rust file.

#### Example
If you have a Rust file `example.rs` in your current directory, you can transpile it as follows:

```sh
docker run --rm -v $(pwd):/app SkySingh04/gocrab:latest /app/example.rs
```

The output file `example.go` will be created in the same directory.

---


## Contributing
Expand Down

0 comments on commit 4ba4797

Please sign in to comment.