在Travis中编译App Engine应用程序

huangapple go评论78阅读模式
英文:

Compile App Engine application in Travis

问题

有没有办法在使用Go编写的App Engine应用程序上运行编译器,而不需要继续使用开发服务器来提供应用程序,并且能够获取退出代码?

因为我想在Travis的自动化测试中添加一个检查,确保应用程序实际上可以编译。

**澄清一下:**我在Travis中可以访问App Engine SDK / 开发服务器,但我不想运行goapp serve,因为它永远不会退出。

英文:

Is there any way to run the compiler on an App Engine application written in Go without continue to serve the application with the development server and instead get an exit code?

Because I want to add a check in my automated tests in Travis that the application actually compiles.

To clarify: I have access to the App Engine SDK / Development Server in Travis, but I dont want to run goapp serve since it never exits.

答案1

得分: 3

你的解决方案看起来很不正规,没有实际实施测试。为什么不使用goapp build呢?这是我的.travis.yml文件:

language: go
go:
- 1.2.1

# 获取最新版本并下载
install:
    - export FILE=go_appengine_sdk_linux_amd64-$(curl https://appengine.google.com/api/updatecheck | grep release | grep -o '[0-9\.]*').zip
    - curl -O https://storage.googleapis.com/appengine-sdks/featured/$FILE
    - unzip -q $FILE

# 运行构建和测试
script:
    - ./go_appengine/goapp test ./tests; # 如果你正在进行测试
    - ./go_appengine/goapp build ./packagedir; # 你保存东西的地方

[用于测试或查看构建项目的参考][1]

编辑:
-----

已经过了一段时间,但我最近注意到我的一些构建会随机失败。这真是令人恼火,我偶尔会硬编码SDK的值来解决这个问题。不再这样做了。这是一个非常不正规的实现,用于获取所需SDK的第一个特色版本(因为/updatecheck无法始终返回托管版本):

```bash
export FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -o 'featured/go_appengine_sdk_linux_amd64-[^\<]*' | head -1)

只获取文件名:

export FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -oP '(?<=featured/)go_appengine_sdk_linux_amd64-[^\<]*' | head -1)

<details>
<summary>英文:</summary>

Without actually implementing test, your solution looks pretty hacky. Why not use `goapp build`? Here&#39;s my `.travis.yml`:

    language: go
    go:
    - 1.2.1

    # Grab newest version and suck down
    install:
        - export FILE=go_appengine_sdk_linux_amd64-$(curl https://appengine.google.com/api/updatecheck | grep release | grep -o &#39;[0-9\.]*&#39;).zip
        - curl -O https://storage.googleapis.com/appengine-sdks/featured/$FILE
        - unzip -q $FILE

    # Run build and tests
    script:
        - ./go_appengine/goapp test ./tests; # If you are testing
        - ./go_appengine/goapp build ./packagedir; # Wherever you keep your stuff

[For reference on tests or just to see a project that builds][1]

Edit:
-----

It has been awhile, but I noticed recently that some of my builds randomly break. It is infuriating and I have occasionally hardcoded SDK values to overcome this. No more. Here&#39;s a very hacky implementation of grabbing the first featured (and thus hosted as /updatecheck fails to always return a hosted version) of the SDK desired:

    export FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -o &#39;featured/go_appengine_sdk_linux_amd64-[^\&lt;]*&#39; | head -1)

For just the file:

    export FILE=$(curl https://storage.googleapis.com/appengine-sdks/ | grep -oP &#39;(?&lt;=featured/)go_appengine_sdk_linux_amd64-[^\&lt;]*&#39; | head -1)

  [1]: https://github.com/dmadisetti/noughtscrosses

</details>



# 答案2
**得分**: 0

我通过在应用程序的入口点(main_test.go)添加一个空的单元测试来解决了这个问题。这个单元测试将强制整个应用程序进行编译。

然后,我通过在**script**部分中添加**goapp test ./...**来执行所有的单元测试。

<details>
<summary>英文:</summary>

I solved this by adding an empty Unit test at the entry point of the application (main_test.go). This unit test will force the whole application to compile.

Then I execute all unit tests by putting **goapp test ./...** in the **script** section.

</details>



huangapple
  • 本文由 发表于 2014年7月7日 23:46:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/24614599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定