From 80741c0c8c1ced9561aac6b9103ada4685d42dd3 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 18 Apr 2022 16:36:21 -0400 Subject: [PATCH 1/3] Add minimal smoke test --- .github/workflows/build.yml | 49 +++++++++++++++++++++++++++++++ .github/workflows/test.yml | 57 ++++++++++++------------------------- 2 files changed, 67 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..9029f74 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,49 @@ +name: build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go: [ '1.17', '1.18' ] + name: go build with ${{ matrix.go }} + steps: + - uses: actions/checkout@v3 + + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go }} + + - name: Vet + run: go vet ./... + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... -race + + tag: + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + name: Tag + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Create tag + uses: actions/github-script@v5 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/v1.0.${{ github.run_number }}', + sha: context.sha + }) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77e892b..c9ccd23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,49 +1,28 @@ name: test on: - push: - branches: [ main ] pull_request: branches: [ main ] jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - go: [ '1.17', '1.18' ] - name: go build with ${{ matrix.go }} + setup: + runs-on: ubuntu-18.04 + name: setup steps: - uses: actions/checkout@v3 - - - name: Setup go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go }} - - - name: Vet - run: go vet ./... - - - name: Build - run: go build -v ./... - - - name: Test - run: go test -v ./... -race - - tag: - if: github.ref == 'refs/heads/main' && github.event_name == 'push' - name: Tag - needs: build - runs-on: ubuntu-latest + - name: Build the stack + run: docker-compose up -d + + test: + runs-on: ubuntu-18.04 + needs: setup steps: - - uses: actions/checkout@v3 - - name: Create tag - uses: actions/github-script@v5 - with: - script: | - github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: 'refs/tags/v1.0.${{ github.run_number }}', - sha: context.sha - }) + - name: Test Hello + run: | + docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused \ + http://localhost:3000/hello + - name: Test Trial + run: | + docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused \ + -H 'Content-Type: application/json' -d '{"action": "hop", "time": 100}' -X POST http://localhost:3000/scores/trial && \ + curl -s http://localhost:3000/scores/trial/average | grep "hop" From 256369fdb8e60149bdd572bf5b5293c51c4ec4d3 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 18 Apr 2022 16:42:10 -0400 Subject: [PATCH 2/3] Github actions destroys containers between steps --- .github/workflows/test.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9ccd23..cd8aeee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,24 +5,19 @@ on: branches: [ main ] jobs: - setup: + test: runs-on: ubuntu-18.04 - name: setup steps: - uses: actions/checkout@v3 - name: Build the stack run: docker-compose up -d - - test: - runs-on: ubuntu-18.04 - needs: setup - steps: - name: Test Hello run: | docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused \ - http://localhost:3000/hello + http://localhost:3000/hello - name: Test Trial run: | docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused \ -H 'Content-Type: application/json' -d '{"action": "hop", "time": 100}' -X POST http://localhost:3000/scores/trial && \ - curl -s http://localhost:3000/scores/trial/average | grep "hop" + curl -s http://localhost:3000/scores/trial/average | grep "hop" + From ad01e336d057a8f2e4500636c8e34b8e50f90cb6 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 18 Apr 2022 16:49:42 -0400 Subject: [PATCH 3/3] try again --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd8aeee..f0f05ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,7 @@ jobs: run: docker-compose up -d - name: Test Hello run: | - docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused \ - http://localhost:3000/hello + docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused http://localhost:3000/hello - name: Test Trial run: | docker run --network container:scorekeeper-api appropriate/curl -s --retry 10 --retry-connrefused \