-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from PedroHenriques/initial_version
initial version of the application
- Loading branch information
Showing
43 changed files
with
4,011 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: cd | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Clone repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build application | ||
run: sh cli/build.sh build | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_ACCESS_KEY_SECRET }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Get runner ip address | ||
id: ip | ||
uses: haythem/[email protected] | ||
|
||
- name: Whitelist runner ip address | ||
run: | | ||
aws ec2 authorize-security-group-ingress \ | ||
--group-id ${{ secrets.AWS_SG_ID }} \ | ||
--protocol tcp \ | ||
--port 22 \ | ||
--cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: Upload the linux binary to the remote server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USER }} | ||
key: ${{ secrets.KEY }} | ||
source: "bin/linux/go-minesweeper.zip" | ||
target: ${{ secrets.REMOTE_TARGET_PATH }} | ||
strip_components: 1 | ||
|
||
- name: Revoke runner ip address | ||
run: | | ||
aws ec2 revoke-security-group-ingress \ | ||
--group-id ${{ secrets.AWS_SG_ID }} \ | ||
--protocol tcp \ | ||
--port 22 \ | ||
--cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
if: ${{ always() }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: ci | ||
on: | ||
pull_request: | ||
types: [opened, edited, reopened, synchronize] | ||
push: | ||
branches: | ||
- 'main' | ||
jobs: | ||
linter-and-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Clone repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run linter | ||
run: sh cli/lint.sh build | ||
|
||
- name: Run unit tests | ||
run: sh cli/test.sh build | ||
|
||
- name: Run unit test coverage | ||
run: sh cli/coverage.sh | ||
|
||
- name: Coveralls | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
path-to-lcov: "./coverage/coverage.lcov" | ||
flag-name: "unit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
go.work | ||
go.work.sum | ||
|
||
coverage/ | ||
|
||
fyneBundle.go | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Options for analysis running. | ||
run: | ||
# Include test files or not. | ||
# Default: true | ||
tests: false | ||
# Allow multiple parallel golangci-lint instances running. | ||
# If false (default) - golangci-lint acquires file lock on start. | ||
allow-parallel-runners: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Details] | ||
Icon = "assets/images/favicon.png" | ||
Name = "Go_Minesweeper" | ||
ID = "com.github.go-minesweeper" | ||
Version = "1.0.0" | ||
Build = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,86 @@ | ||
# go-minesweeper | ||
A minesweeper game built in Go. | ||
[![Coverage Status](https://coveralls.io/repos/github/PedroHenriques/go-minesweeper/badge.svg?branch=main)](https://coveralls.io/github/PedroHenriques/go-minesweeper?branch=main) | ||
|
||
# Go Minesweeper | ||
|
||
## How to play | ||
|
||
Your goal is to reveal all the tiles that don't have a mine. | ||
Revealed tiles that are adjacent to mines will have a number. This number indicates how many mines are in adjacent tiles. | ||
|
||
- left mouse button: reveals a tile | ||
- right mouse button: adds/removes a flag from a tile, preventing it from being revealed | ||
- left + right mouse buttons (on a revealed tile): reveales all adjacent tiles, only if enough flags are placed. This function prevents acidental mine hits. | ||
|
||
## Binaries | ||
|
||
You can download the binaries [here](http://pedrojhenriques.com/games/go-minesweeper/) | ||
|
||
## Building the binaries | ||
|
||
### Prerequisites | ||
|
||
- **Docker:** Install documentation [here](https://docs.docker.com/get-docker/) | ||
|
||
### Building the binaries | ||
|
||
On a terminal, from the root of the repo, run | ||
```sh | ||
sh cli/build.sh [build] | ||
|
||
build: will build the docker image used to compile the code | ||
``` | ||
|
||
The binaries will be available on the directory `bin/` | ||
|
||
## Run the game from source | ||
|
||
### Prerequisites | ||
|
||
1. Make sure you have the latest version of golang installed | ||
|
||
2. Install Fyne, the graphic library used to render the GUI | ||
```sh | ||
go install fyne.io/fyne/v2/cmd/fyne@latest | ||
``` | ||
|
||
3. Install Fyne's dependencies for your OS. Consult them [here](https://developer.fyne.io/started/#prerequisites) | ||
|
||
### Running the game | ||
|
||
On a terminal, from the root of the repo, run | ||
```sh | ||
sh cli/run.sh | ||
``` | ||
|
||
## Development tools | ||
|
||
### Running the linters | ||
|
||
On a terminal, from the root of the repo, run | ||
```sh | ||
sh cli/lint.sh [build] | ||
|
||
build: will build the docker image used to run the linters | ||
``` | ||
|
||
### Running the tests | ||
|
||
On a terminal, from the root of the repo, run | ||
```sh | ||
sh cli/test.sh [build] [-w] [dir1 dir2 ...] | ||
|
||
build: will build the docker image used to run the tests | ||
-w: run the tests in watch mode | ||
dir1 dir2 ...: the directories to look for test files. Default is internal/ | ||
``` | ||
|
||
### Running the test coverage | ||
|
||
On a terminal, from the root of the repo, run | ||
```sh | ||
sh cli/coverage.sh [build] | ||
|
||
build: will build the docker image used to run the tests | ||
``` | ||
|
||
The output will be available on the directory `coverage/` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
BUILD_DOCKER_IMG=0 | ||
if [ "$1" = "build" ]; | ||
then | ||
BUILD_DOCKER_IMG=1 | ||
fi | ||
|
||
mkdir -p ./bin/linux/; | ||
mkdir -p ./bin/windows/; | ||
mkdir -p ./bin/macos/; | ||
|
||
echo "Building app for the current OS"; | ||
|
||
if [ $BUILD_DOCKER_IMG -eq 1 ]; | ||
then | ||
echo "Build the Docker image"; | ||
docker build -f ./docker/Dockerfile-linux --pull --rm -t go-minesweeper-linux:latest .; | ||
fi | ||
|
||
echo "Running Docker container to build app"; | ||
docker run --rm -v "${PWD}/bin/":"/usr/src/app/bin/" go-minesweeper-linux:latest /bin/sh -c "go build -o ./bin/linux/ && zip -jm ./bin/linux/go-minesweeper.zip ./bin/linux/go-minesweeper"; | ||
|
||
echo "Finished building app" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
cd ./assets/images/; | ||
|
||
APPEND=0; | ||
|
||
for file in * ; do | ||
if [ $APPEND -eq 1 ]; then | ||
fyne bundle -a -o ../../internal/gui/fyneBundle.go $file; | ||
else | ||
fyne bundle --pkg gui -o ../../internal/gui/fyneBundle.go $file; | ||
|
||
APPEND=1; | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
BUILD_DOCKER_IMG=0 | ||
DIRS=""; | ||
|
||
if [ "$1" != "" ]; then | ||
if [ "$1" = "build" ]; then | ||
BUILD_DOCKER_IMG=1 | ||
else | ||
DIRS=$1; | ||
fi | ||
fi | ||
|
||
if [ $BUILD_DOCKER_IMG -eq 1 ]; then | ||
echo "Build the Docker image"; | ||
docker build -f ./docker/Dockerfile-linux --pull --rm -t go-minesweeper-linux:latest .; | ||
fi | ||
|
||
if [ "$DIRS" = "" ]; then | ||
for dir in ./internal/*/ ; do | ||
DIRS="$DIRS $dir"; | ||
done | ||
fi | ||
|
||
mkdir -p ./coverage/; | ||
|
||
docker run --rm -v "${PWD}/":"/usr/src/app/" go-minesweeper-linux:latest /bin/sh -c "go test -coverprofile coverage/coverage.out $DIRS && go tool cover -html coverage/coverage.out -o coverage/coverage.html && gcov2lcov -infile=coverage/coverage.out -outfile=coverage/coverage.lcov"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
BUILD_DOCKER_IMG=0 | ||
if [ "$1" = "build" ]; then | ||
BUILD_DOCKER_IMG=1 | ||
fi | ||
|
||
if [ $BUILD_DOCKER_IMG -eq 1 ]; then | ||
echo "Build the Docker image"; | ||
docker build -f ./docker/Dockerfile-linter --pull --rm -t go-minesweeper-linter:latest .; | ||
fi | ||
|
||
docker run --rm -v "${PWD}/":"/usr/src/app/" go-minesweeper-linter:latest /bin/sh -c "go mod tidy && sh ./cli/bundle.sh && golangci-lint run -v"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Generate the Fyne bundle file with all the necessary assets | ||
sh ./cli/bundle.sh; | ||
|
||
# Compile and run the application | ||
go run ./main.go; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
BUILD_DOCKER_IMG=0 | ||
DIRS=""; | ||
WATCH=0; | ||
|
||
if [ "$1" != "" ]; then | ||
if [ "$1" = "build" ]; then | ||
BUILD_DOCKER_IMG=1 | ||
else | ||
if [ "$1" = "-w" ]; then | ||
WATCH=1 | ||
elif [ "$2" = "" ]; then | ||
DIRS=$1; | ||
fi | ||
fi | ||
fi | ||
|
||
if [ $BUILD_DOCKER_IMG -eq 1 ]; then | ||
echo "Build the Docker image"; | ||
docker build -f ./docker/Dockerfile-linux --pull --rm -t go-minesweeper-linux:latest .; | ||
fi | ||
|
||
if [ "$2" != "" ]; then | ||
DIRS=$2; | ||
fi | ||
|
||
if [ "$DIRS" = "" ]; then | ||
for dir in ./internal/*/ ; do | ||
DIRS="$DIRS $dir"; | ||
done | ||
fi | ||
|
||
if [ $WATCH -eq 1 ]; then | ||
docker run --rm -v "${PWD}/":"/usr/src/app/" go-minesweeper-linux:latest /bin/sh -c "gow -c test -v -cover $DIRS"; | ||
else | ||
docker run --rm -v "${PWD}/":"/usr/src/app/" go-minesweeper-linux:latest /bin/sh -c "go test -v -cover $DIRS"; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"SizeOptions": { | ||
"Beginner (9x9 - 10 mines)": { "NumMines": 10, "NumRows": 9, "NumCols": 9 }, | ||
"Intermediate (16x16 - 40 mines)": { "NumMines": 40, "NumRows": 16, "NumCols": 16 }, | ||
"Expert (16x30 - 99 mines)": { "NumMines": 99, "NumRows": 16, "NumCols": 30 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM golangci/golangci-lint:v1.50 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Install system dependencies | ||
RUN apt-get update && apt-get install -y gcc libgl1-mesa-dev xorg-dev | ||
|
||
# Install Fyne CLI | ||
RUN go install fyne.io/fyne/v2/cmd/fyne@latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
FROM golang:1.19-buster | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Install system dependencies | ||
RUN apt-get update && apt-get install -y gcc libgl1-mesa-dev xorg-dev zip | ||
|
||
# Copy the repo into the container | ||
ADD . . | ||
|
||
# Install GO dependencies | ||
RUN go mod tidy | ||
|
||
# Install Fyne CLI | ||
RUN go install fyne.io/fyne/v2/cmd/fyne@latest | ||
|
||
# Install dependency needed for converting coverage output into lcov format | ||
RUN go install github.com/jandelgado/gcov2lcov@latest | ||
|
||
# Install dependency needed for running tests in watch mode | ||
RUN go install github.com/mitranim/gow@latest | ||
|
||
# Generate the Fyne bundle file with all the necessary assets | ||
RUN sh ./cli/bundle.sh |
Oops, something went wrong.