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 Jan 22, 2025
2 parents f13da3c + ed5b3f1 commit a313c21
Show file tree
Hide file tree
Showing 82 changed files with 2,326 additions and 501 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/build_copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: copier-build
on:
workflow_run:
workflows: [ci-worker]
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.workflow_run.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 "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
if [[ "$BRANCH" = "release" ]]; then
TAG=$(git tag --points-at HEAD)
if [[ ! -z "$TAG" ]]; then
echo "new_tag=$TAG" >> "$GITHUB_OUTPUT"
echo "new_tag_short=${TAG#v}" >> "$GITHUB_OUTPUT"
else
echo "name=rc" >> "$GITHUB_OUTPUT"
fi
else
echo "name=nightly" >> "$GITHUB_OUTPUT"
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-copier
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.new_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 "platforms=$PLATFORMS" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
context: ./worker
file: ./worker/copier.Dockerfile
platforms: ${{ steps.options.outputs.platforms }}
push: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
53 changes: 53 additions & 0 deletions .github/workflows/build_worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,56 @@ jobs:
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max

docker_copier:
runs-on: ubuntu-latest
if: inputs.name || inputs.new_tag
env:
IMAGE_NAME: reearth/reearth-cms-copier
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: ${{ inputs.new_tag_short }}
NAME: ${{ inputs.name }}
SHA: ${{ inputs.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 "platforms=$PLATFORMS" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./worker/copier.Dockerfile
platforms: ${{ steps.options.outputs.platforms }}
push: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
51 changes: 51 additions & 0 deletions .github/workflows/e2e_web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Web E2E test
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * 1-5"
jobs:
e2e:
name: playwright
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: yarn
cache-dependency-path: "**/yarn.lock"
- name: Install dependencies
run: yarn install
- name: Get installed Playwright version
id: playwright-version
run: echo "version=$( node -e "console.log(require('@playwright/test/package.json').version)" )" >> $GITHUB_OUTPUT
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: "${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}"
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright system dependencies and browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: yarn playwright install --with-deps chromium
- name: Install Playwright system dependencies
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: yarn playwright install-deps chromium
- name: Run Playwright tests
run: yarn e2e
env:
REEARTH_CMS_API: https://api.cms.test.reearth.dev/api
REEARTH_CMS_E2E_BASEURL: https://cms.test.reearth.dev
REEARTH_CMS_E2E_USERNAME: ${{ secrets.REEARTH_WEB_E2E_USERNAME }}
REEARTH_CMS_E2E_PASSWORD: ${{ secrets.REEARTH_WEB_E2E_PASSWORD }}
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results
path: web/test-results/
retention-days: 7
5 changes: 2 additions & 3 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ jobs:
if: github.ref == 'refs/heads/main'
steps:
- name: git config
env:
GH_APP_USER: ${{ vars.GH_APP_USER }}
run: |
git config --global user.name $GH_APP_USER
git config --global user.name ${{ vars.GH_APP_USER }}
git config --global user.email ${{ vars.GH_APP_ID }}+${{ vars.GH_APP_USER }}[bot]@users.noreply.github.com
git config --global pull.rebase false
- uses: actions/create-github-app-token@v1
id: app-token
Expand Down
7 changes: 5 additions & 2 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
PORT=8080
REEARTH_CMS_DB=mongodb://localhost
REEARTH_CMS_HOST=https://localhost:8080
REEARTH_CMS_SERVERHOST=https://localhost:8080
REEARTH_CMS_SERVERHOST=localhost
REEARTH_CMS_HOST_WEB=https://localhost:3000
REEARTH_CMS_ASSETBASEURL=https://localhost:8080/assets
REEARTH_CMS_DEV=false
REEARTH_CMS_SIGNUPSECRET=
REEARTH_CMS_ORIGINS=www.example.com,localhost:3000

REEARTH_CMS_DB_ACCOUNT=mongodb://localhost
REEARTH_CMS_DB_ACCOUNT=reearth_account
REEARTH_CMS_DB_CMS=reearth_cms
REEARTH_CMS_DB_USERS=Test1=mongodb://localhost,Test2=mongodb://localhost

#GraphQL
Expand Down Expand Up @@ -96,6 +97,8 @@ REEARTH_CMS_TASK_DECOMPRESSORIMAGE=
REEARTH_CMS_TASK_DECOMPRESSORTOPIC=
REEARTH_CMS_TASK_DECOMPRESSORGZIPEXT=
REEARTH_CMS_TASK_DECOMPRESSORMACHINETYPE=
REEARTH_CMS_TASK_COPIERIMAGE=
REEARTH_CMS_TASK_DBSECRETNAME=

#AWS
REEARTH_CMS_AWSTASK_TOPICARN=
Expand Down
85 changes: 85 additions & 0 deletions server/e2e/integration_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,91 @@ func TestIntegrationModelGetAPI(t *testing.T) {
obj.Value("lastModified").NotNull()
}

// POST /models/{modelId}/copy
func TestIntegrationModelCopy(t *testing.T) {
endpoint := "/api/models/{modelId}/copy"
e := StartServer(t, &app.Config{}, true, baseSeeder)

e.POST(endpoint, id.NewModelID()).
Expect().
Status(http.StatusUnauthorized)

e.POST(endpoint, id.NewModelID()).
WithHeader("authorization", "secret_abc").
Expect().
Status(http.StatusUnauthorized)

e.POST(endpoint, id.NewModelID()).
WithHeader("authorization", "Bearer secret_abc").
Expect().
Status(http.StatusUnauthorized)

oldModelId := mId1.String()
oldModel := e.GET("/api/models/{modelId}", oldModelId).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
Object()

newName := "new name"
newKey := id.RandomKey().Ref().StringRef()
newModel := e.POST(endpoint, oldModelId).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": newName,
"key": newKey,
}).
Expect().
Status(http.StatusOK).
JSON().
Object()

newModel.
ContainsKey("id").
ContainsKey("projectId").
ContainsKey("schemaId").
ContainsKey("public").
ContainsKey("createdAt").
ContainsKey("updatedAt").
ContainsKey("key")

newModelID := newModel.Value("id").String()
newModelID.NotEqual(oldModelId)
copiedModel := e.GET("/api/models/{modelId}", newModelID.Raw()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
Object()
copiedModel.
HasValue("id", newModelID.Raw()).
HasValue("projectId", oldModel.Value("projectId").String().Raw()).
HasValue("public", oldModel.Value("public").Boolean().Raw()).
HasValue("name", newName).
HasValue("key", newKey).
HasValue("description", oldModel.Value("description").String().Raw())

copiedModel.Value("schemaId").NotNull()
oldSchemaId := oldModel.Value("schemaId").String()
copiedSchemaId := copiedModel.Value("schemaId").String()
copiedSchemaId.NotEqual(oldSchemaId.Raw())

oldSchema := oldModel.Value("schema").Object()
copiedSchema := copiedModel.Value("schema").Object()
copiedSchema.Value("fields").Array().Length().IsEqual(oldSchema.Value("fields").Array().Length().Raw())
copiedSchema.Value("titleField").String().IsEqual(oldSchema.Value("titleField").String().Raw())

copiedModel.Value("metadataSchemaId").NotNull()
oldMetadataSchemaId := oldModel.Value("metadataSchemaId").String()
copiedMetadataSchemaId := copiedModel.Value("metadataSchemaId").String()
copiedMetadataSchemaId.NotEqual(oldMetadataSchemaId.Raw())

oldMetadataSchema := oldModel.Value("metadataSchema").Object()
copiedMetadataSchema := copiedModel.Value("metadataSchema").Object()
copiedMetadataSchema.Value("fields").Array().Length().IsEqual(oldMetadataSchema.Value("fields").Array().Length().Raw())
}

// PATCH /models/{modelId}
func TestIntegrationModelUpdateAPI(t *testing.T) {
endpoint := "/api/models/{modelId}"
Expand Down
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/k0kubun/pp/v3 v3.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/labstack/echo/v4 v4.12.0
github.com/labstack/gommon v0.4.2
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/paulmach/go.geojson v1.5.0
Expand Down Expand Up @@ -116,7 +117,6 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/opts v1.2.3 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/maruel/panicparse/v2 v2.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
Loading

0 comments on commit a313c21

Please sign in to comment.