Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
reearth-app[bot] committed Oct 11, 2024
2 parents d887c51 + c7c79a4 commit 78856c5
Show file tree
Hide file tree
Showing 83 changed files with 2,144 additions and 1,438 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ jobs:
run: yarn i18n --fail-on-update
- name: Build
run: yarn build

# TODO: Remove after dockerizing the web.
- name: Pack
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release'
run: mv dist reearth-cms-web && tar -zcvf reearth-cms-web.tar.gz reearth-cms-web

# TODO: Remove after dockerizing the web.
- uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release'
with:
Expand Down
59 changes: 48 additions & 11 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
name: deploy-test
on:
workflow_run:
workflows: [server-build, ci-web, worker-build]
workflows: [server-build, ci-web, web-build, worker-build]
types: [completed]
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}-${{github.event.workflow_run.name}}
cancel-in-progress: true
env:
GCP_REGION: us-central1

# TODO: Remove after dockerizing the web.
GCS_DEST: gs://cms.test.reearth.dev

# server
IMAGE: reearth/reearth-cms:nightly
IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms:nightly
IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms:nightly
SERVER_IMAGE: reearth/reearth-cms:nightly
SERVER_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms:nightly
SERVER_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms:nightly

# web
WEB_IMAGE: reearth/reearth-cms-web:nightly
WEB_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms-web:nightly
WEB_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms-web:nightly

# worker
WORKER_IMAGE: reearth/reearth-cms-worker:nightly
WORKER_IMAGE_NAME: us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/reearth/reearth-cms-worker:nightly
WORKER_IMAGE_GCP: us-central1-docker.pkg.dev/reearth-oss/reearth/reearth-cms-worker:nightly
GCP_REGION: us-central1
GCS_DEST: gs://cms.test.reearth.dev

jobs:
deploy_web:
# TODO: Remove after dockerizing the web.
deploy_web_gcs:
name: Deploy web to test env
if: github.event.repository.full_name == 'reearth/reearth-cms' && github.event.workflow_run.name == 'ci-web' && github.event.workflow_run.conclusion != 'failure' && github.event.workflow_run.head_branch == 'main'
runs-on: ubuntu-latest
Expand Down Expand Up @@ -67,13 +77,40 @@ jobs:
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
- name: docker push
run: |
docker pull $IMAGE
docker tag $IMAGE $IMAGE_GCP
docker push $IMAGE_GCP
docker pull $SERVER_IMAGE
docker tag $SERVER_IMAGE $SERVER_IMAGE_GCP
docker push $SERVER_IMAGE_GCP
- name: Deploy to Cloud Run
run: |
gcloud run deploy reearth-cms-backend \
--image $IMAGE_GCP \
--image $SERVER_IMAGE_GCP \
--region $GCP_REGION \
--platform managed \
--quiet
deploy_web:
name: Deploy web to test env
runs-on: ubuntu-latest
if: github.event.repository.full_name == 'reearth/reearth-cms' && github.event.workflow_run.name == 'web-build' && github.event.workflow_run.conclusion != 'failure' && github.event.workflow_run.head_branch == 'main'
steps:
- uses: actions/checkout@v4

- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure docker
run: gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
- name: docker push
run: |
docker pull $WEB_IMAGE
docker tag $WEB_IMAGE $WEB_IMAGE_GCP
docker push $WEB_IMAGE_GCP
- name: Deploy to Cloud Run
run: |
gcloud run deploy reearth-cms-web \
--image $WEB_IMAGE_GCP \
--region $GCP_REGION \
--platform managed \
--quiet
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/web_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: web-build
on:
workflow_run:
workflows: [ci-web]
types: [completed]
branches: [main, release]
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true

jobs:
info:
name: Collect information
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'failure' && github.event.repository.full_name == 'reearth/reearth-cms' && (github.event.workflow_run.head_branch == 'release' || !startsWith(github.event.head_commit.message, 'v'))
outputs:
sha_short: ${{ steps.info.outputs.sha_short }}
new_tag: ${{ steps.info.outputs.new_tag }}
new_tag_short: ${{ steps.info.outputs.new_tag_short }}
name: ${{ steps.info.outputs.name }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: Fetch tags
run: git fetch --prune --unshallow --tags
- name: Get info
id: info
# The tag name should be retrieved lazily, as tagging may be delayed.
env:
BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
if [[ "$BRANCH" = "release" ]]; then
TAG=$(git tag --points-at HEAD)
if [[ ! -z "$TAG" ]]; then
echo "::set-output name=new_tag::$TAG"
echo "::set-output name=new_tag_short::${TAG#v}"
else
echo "::set-output name=name::rc"
fi
else
echo "::set-output name=name::nightly"
fi
- name: Show info
env:
SHA_SHORT: ${{ steps.info.outputs.sha_short }}
NEW_TAG: ${{ steps.info.outputs.new_tag }}
NEW_TAG_SHORT: ${{ steps.info.outputs.new_tag_short }}
NAME: ${{ steps.info.outputs.name }}
run: echo "sha_short=$SHA_SHORT, new_tag=$NEW_TAG, new_tag_short=$NEW_TAG_SHORT, name=$NAME"

docker:
name: Build and push Docker image
runs-on: ubuntu-latest
needs:
- info
if: needs.info.outputs.name || needs.info.outputs.new_tag
env:
IMAGE_NAME: reearth/reearth-cms-web
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get options
id: options
env:
TAG: ${{ needs.info.outputs.tag_short }}
NAME: ${{ needs.info.outputs.name }}
SHA: ${{ needs.info.outputs.sha_short }}
run: |
if [[ -n $TAG ]]; then
PLATFORMS=linux/amd64,linux/arm64
VERSION=$TAG
TAGS=$IMAGE_NAME:$TAG
if [[ ! $TAG =~ '-' ]]; then
TAGS+=,${IMAGE_NAME}:${TAG%.*}
TAGS+=,${IMAGE_NAME}:${TAG%%.*}
TAGS+=,${IMAGE_NAME}:latest
fi
else
PLATFORMS=linux/amd64
VERSION=$SHA
TAGS=$IMAGE_NAME:$NAME
fi
echo "::set-output name=platforms::$PLATFORMS"
echo "::set-output name=version::$VERSION"
echo "::set-output name=tags::$TAGS"
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
context: ./web
platforms: ${{ steps.options.outputs.platforms }}
push: true
build-args: |
GITHUB_SHA=${{ needs.info.outputs.sha_short }}
VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
21 changes: 21 additions & 0 deletions server/e2e/integration_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
wId0 = accountdomain.NewWorkspaceID()
uId = accountdomain.NewUserID()
iId = id.NewIntegrationID()
mId0 = id.NewModelID()
mId1 = id.NewModelID()
mId2 = id.NewModelID()
mId3 = id.NewModelID()
Expand Down Expand Up @@ -72,7 +73,9 @@ var (
ikey2 = key.Random()
ikey3 = key.Random()
ikey4 = key.Random()
ikey0 = id.RandomKey()
pid = id.NewProjectID()
sid0 = id.NewSchemaID()
sid1 = id.NewSchemaID()
sid2 = id.NewSchemaID()
sid3 = id.NewSchemaID()
Expand Down Expand Up @@ -153,6 +156,11 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
sf3 := schema.NewField(schema.NewReference(mId1, sid1, nil, nil).TypeProperty()).ID(fId3).Key(sfKey3).MustBuild()
sf4 := schema.NewField(schema.NewBool().TypeProperty()).ID(fId4).Key(sfKey4).MustBuild()

s0 := schema.New().ID(sid0).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{}).MustBuild()
if err := r.Schema.Save(ctx, s0); err != nil {
return err
}

s1 := schema.New().ID(sid1).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{sf1, sf2}).TitleField(sf1.ID().Ref()).MustBuild()
if err := r.Schema.Save(ctx, s1); err != nil {
return err
Expand All @@ -168,6 +176,19 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
return err
}

m0 := model.New().
ID(mId0).
Name("m0").
Description("m0 desc").
Public(true).
Key(ikey0).
Project(p.ID()).
Schema(s0.ID()).
MustBuild()
if err := r.Model.Save(ctx, m0); err != nil {
return err
}

m1 := model.New().
ID(mId1).
Name("m1").
Expand Down
40 changes: 35 additions & 5 deletions server/e2e/integration_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,27 @@ func TestIntegrationModelUpdateAPI(t *testing.T) {
Expect().
Status(http.StatusUnauthorized)

obj := e.PATCH(endpoint, mId1).
// update empty model
obj := e.PATCH(endpoint, mId0).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": "M0 updated",
"description": "M0 desc updated",
"key": "M0KeyUpdated",
}).
Expect().
Status(http.StatusOK).
JSON().
Object()
obj.
ContainsKey("id").
ContainsKey("schemaId").
HasValue("projectId", pid).
HasValue("name", "M0 updated").
HasValue("description", "M0 desc updated").
HasValue("key", "M0KeyUpdated")

obj = e.PATCH(endpoint, mId1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": "newM1 updated",
Expand Down Expand Up @@ -187,12 +207,22 @@ func TestIntegrationModelFilterAPI(t *testing.T) {
Object().
HasValue("page", 1).
HasValue("perPage", 10).
HasValue("totalCount", 5).
HasValue("totalCount", 6).
Value("models").
Array()
models.Length().IsEqual(5)
models.Length().IsEqual(6)

obj0 := models.Value(0).Object()
obj0.
HasValue("id", mId0.String()).
HasValue("name", "m0").
HasValue("description", "m0 desc").
HasValue("public", true).
HasValue("key", ikey0.String()).
HasValue("projectId", pid).
HasValue("schemaId", sid0)

obj1 := models.Value(0).Object()
obj1 := models.Value(1).Object()
obj1.
HasValue("id", mId1.String()).
HasValue("name", "m1").
Expand All @@ -206,7 +236,7 @@ func TestIntegrationModelFilterAPI(t *testing.T) {
obj1.Value("updatedAt").NotNull()
obj1.Value("lastModified").NotNull()

obj2 := models.Value(1).Object()
obj2 := models.Value(2).Object()
obj2.
HasValue("id", mId2.String()).
HasValue("name", "m2").
Expand Down
18 changes: 14 additions & 4 deletions server/e2e/integration_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@ func TestIntegrationScemaFilterAPI(t *testing.T) {
Object().
HasValue("page", 1).
HasValue("perPage", 10).
HasValue("totalCount", 5).
HasValue("totalCount", 6).
Value("models").
Array()
models.Length().IsEqual(5)
models.Length().IsEqual(6)

obj1 := models.Value(0).Object()
obj0 := models.Value(0).Object()
obj0.
HasValue("id", mId0.String()).
HasValue("name", "m0").
HasValue("description", "m0 desc").
HasValue("public", true).
HasValue("key", ikey0.String()).
HasValue("projectId", pid).
HasValue("schemaId", sid0)

obj1 := models.Value(1).Object()
obj1.
HasValue("id", mId1.String()).
HasValue("name", "m1").
Expand All @@ -62,7 +72,7 @@ func TestIntegrationScemaFilterAPI(t *testing.T) {
obj1.Value("updatedAt").NotNull()
obj1.Value("lastModified").NotNull()

obj2 := models.Value(1).Object()
obj2 := models.Value(2).Object()
obj2.
HasValue("id", mId2.String()).
HasValue("name", "m2").
Expand Down
2 changes: 1 addition & 1 deletion server/internal/adapter/integration/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *Server) ModelUpdate(ctx context.Context, request ModelUpdateRequestObje
}

lastModified, err := uc.Item.LastModifiedByModel(ctx, request.ModelId, op)
if err != nil {
if err != nil && !errors.Is(err, rerror.ErrNotFound) {
return nil, err
}

Expand Down
11 changes: 11 additions & 0 deletions web/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*

!docker/
!src/

!index.html
!i18next-parser.config.js
!tsconfig.json
!package.json
!vite.config.ts
!yarn.lock
Loading

0 comments on commit 78856c5

Please sign in to comment.