Skip to content

Commit

Permalink
Merge remote-tracking branch 'teritori/master' into daosdk
Browse files Browse the repository at this point in the history
  • Loading branch information
n0izn0iz committed Apr 11, 2024
2 parents 1f0f2b6 + 35a29a5 commit d88b16d
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 61 deletions.
100 changes: 51 additions & 49 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,71 @@ concurrency:
cancel-in-progress: true

jobs:
build-push:
build-main:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build main Docker image
env:
owner: ${{ github.repository_owner }}
reponame: ${{ github.event.repository.name }}
run: |
docker build -t ghcr.io/${owner}/${reponame} .
docker tag ghcr.io/${owner}/${reponame}:latest ghcr.io/${owner}/${reponame}:${GITHUB_SHA::8}
- name: Get commit SHA
id: commit
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"

- name: Build slim Docker images
env:
owner: ${{ github.repository_owner }}
reponame: ${{ github.event.repository.name }}
run: |
docker build --target=gnoland-slim -t ghcr.io/${owner}/${reponame}/gnoland-slim .
docker build --target=gnokey-slim -t ghcr.io/${owner}/${reponame}/gnokey-slim .
docker build --target=gno-slim -t ghcr.io/${owner}/${reponame}/gno-slim .
docker build --target=gnofaucet-slim -t ghcr.io/${owner}/${reponame}/gnofaucet-slim .
docker build --target=gnoweb-slim -t ghcr.io/${owner}/${reponame}/gnoweb-slim .
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

docker tag ghcr.io/${owner}/${reponame}/gnoland-slim:latest ghcr.io/${owner}/${reponame}/gnoland-slim:${GITHUB_SHA::8}
docker tag ghcr.io/${owner}/${reponame}/gnokey-slim:latest ghcr.io/${owner}/${reponame}/gnokey-slim:${GITHUB_SHA::8}
docker tag ghcr.io/${owner}/${reponame}/gno-slim:latest ghcr.io/${owner}/${reponame}/gno-slim:${GITHUB_SHA::8}
docker tag ghcr.io/${owner}/${reponame}/gnofaucet-slim:latest ghcr.io/${owner}/${reponame}/gnofaucet-slim:${GITHUB_SHA::8}
docker tag ghcr.io/${owner}/${reponame}/gnoweb-slim:latest ghcr.io/${owner}/${reponame}/gnoweb-slim:${GITHUB_SHA::8}
- name: List docker images
run: |
docker images | grep ghcr
- name: Log in to GitHub Container Registry
if: (github.event_name != 'pull_request')
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: (github.event_name != 'pull_request')
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.commit.outputs.sha }}
- name: Publish images
if: (github.event_name != 'pull_request')
env:
owner: ${{ github.repository_owner }}
reponame: ${{ github.event.repository.name }}
run: |
docker push ghcr.io/${owner}/${reponame}:latest
docker push ghcr.io/${owner}/${reponame}:${GITHUB_SHA::8}
docker push ghcr.io/${owner}/${reponame}/gnoland-slim:latest
docker push ghcr.io/${owner}/${reponame}/gnoland-slim:${GITHUB_SHA::8}
build-slim:
runs-on: ubuntu-latest
strategy:
matrix:
target: [gnoland-slim, gnokey-slim, gno-slim, gnofaucet-slim, gnoweb-slim]
steps:
- name: Checkout
uses: actions/checkout@v4

docker push ghcr.io/${owner}/${reponame}/gnokey-slim:latest
docker push ghcr.io/${owner}/${reponame}/gnokey-slim:${GITHUB_SHA::8}
- name: Get commit SHA
id: commit
run: echo "sha=${GITHUB_SHA::8}" >> "$GITHUB_OUTPUT"

docker push ghcr.io/${owner}/${reponame}/gno-slim:latest
docker push ghcr.io/${owner}/${reponame}/gno-slim:${GITHUB_SHA::8}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

docker push ghcr.io/${owner}/${reponame}/gnofaucet-slim:latest
docker push ghcr.io/${owner}/${reponame}/gnofaucet-slim:${GITHUB_SHA::8}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

docker push ghcr.io/${owner}/${reponame}/gnoweb-slim:latest
docker push ghcr.io/${owner}/${reponame}/gnoweb-slim:${GITHUB_SHA::8}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: (github.event_name != 'pull_request')
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
target: ${{ matrix.target }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:latest
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/${{ matrix.target }}:${{ steps.commit.outputs.sha }}
3 changes: 3 additions & 0 deletions examples/gno.land/p/demo/todolist/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gno.land/p/demo/todolist

require gno.land/p/demo/avl v0.0.0-latest
63 changes: 63 additions & 0 deletions examples/gno.land/p/demo/todolist/todolist.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package todolist

import (
"std"
"strconv"

"gno.land/p/demo/avl"
)

type TodoList struct {
Title string
Tasks *avl.Tree
Owner std.Address
}

type Task struct {
Title string
Done bool
}

func NewTodoList(title string) *TodoList {
return &TodoList{
Title: title,
Tasks: avl.NewTree(),
Owner: std.GetOrigCaller(),
}
}

func NewTask(title string) *Task {
return &Task{
Title: title,
Done: false,
}
}

func (tl *TodoList) AddTask(id int, task *Task) {
tl.Tasks.Set(strconv.Itoa(id), task)
}

func ToggleTaskStatus(task *Task) {
task.Done = !task.Done
}

func (tl *TodoList) RemoveTask(taskId string) {
tl.Tasks.Remove(taskId)
}

func (tl *TodoList) GetTasks() []*Task {
tasks := make([]*Task, 0, tl.Tasks.Size())
tl.Tasks.Iterate("", "", func(key string, value interface{}) bool {
tasks = append(tasks, value.(*Task))
return false
})
return tasks
}

func (tl *TodoList) GetTodolistOwner() std.Address {
return tl.Owner
}

func (tl *TodoList) GetTodolistTitle() string {
return tl.Title
}
81 changes: 81 additions & 0 deletions examples/gno.land/p/demo/todolist/todolist_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package todolist

import (
"std"
"testing"
)

func TestNewTodoList(t *testing.T) {
title := "My Todo List"
todoList := NewTodoList(title)

if todoList.GetTodolistTitle() != title {
t.Errorf("Expected title %q, got %q", title, todoList.GetTodolistTitle())
}

if len(todoList.GetTasks()) != 0 {
t.Errorf("Expected 0 tasks, got %d", len(todoList.GetTasks()))
}

if todoList.GetTodolistOwner() != std.GetOrigCaller() {
t.Errorf("Expected owner %v, got %v", std.GetOrigCaller(), todoList.GetTodolistOwner())
}
}

func TestNewTask(t *testing.T) {
title := "My Task"
task := NewTask(title)

if task.Title != title {
t.Errorf("Expected title %q, got %q", title, task.Title)
}

if task.Done {
t.Errorf("Expected task to be not done, but it is done")
}
}

func TestAddTask(t *testing.T) {
todoList := NewTodoList("My Todo List")
task := NewTask("My Task")

todoList.AddTask(1, task)

tasks := todoList.GetTasks()
if len(tasks) != 1 {
t.Errorf("Expected 1 task, got %d", len(tasks))
}

if tasks[0] != task {
t.Errorf("Expected task %v, got %v", task, tasks[0])
}
}

func TestToggleTaskStatus(t *testing.T) {
task := NewTask("My Task")

ToggleTaskStatus(task)

if !task.Done {
t.Errorf("Expected task to be done, but it is not done")
}

ToggleTaskStatus(task)

if task.Done {
t.Errorf("Expected task to be not done, but it is done")
}
}

func TestRemoveTask(t *testing.T) {
todoList := NewTodoList("My Todo List")
task := NewTask("My Task")
todoList.AddTask(1, task)

todoList.RemoveTask("1")

tasks := todoList.GetTasks()
if len(tasks) != 0 {
t.Errorf("Expected 0 tasks, got %d", len(tasks))
}
}
8 changes: 8 additions & 0 deletions examples/gno.land/r/demo/todolist/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module gno.land/r/demo/todolist

require (
gno.land/p/demo/avl v0.0.0-latest
gno.land/p/demo/seqid v0.0.0-latest
gno.land/p/demo/todolist v0.0.0-latest
gno.land/p/demo/ufmt v0.0.0-latest
)
Loading

0 comments on commit d88b16d

Please sign in to comment.