|
| 1 | +name: Docker Run Action Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +jobs: |
| 10 | + smoke-test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v2 |
| 14 | + - name: Run docker action and set output for testing |
| 15 | + uses: ./ |
| 16 | + id: run-docker |
| 17 | + with: |
| 18 | + image: docker:20.10.3 |
| 19 | + run: | |
| 20 | + echo "::set-output name=docker-version::`echo $DOCKER_VERSION`" |
| 21 | + - name: Test the output |
| 22 | + uses: actions/github-script@v3 |
| 23 | + with: |
| 24 | + script: | |
| 25 | + const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}'; |
| 26 | + if (dockerVersion !== '20.10.3') { |
| 27 | + core.setFailed(`Smoke Test Failed`); |
| 28 | + } |
| 29 | + volume-mount-test: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v2 |
| 33 | + - name: Create File to be mounted |
| 34 | + run: echo "some text" > someFile |
| 35 | + - name: Run docker action with mounted workspace |
| 36 | + uses: ./ |
| 37 | + id: run-docker |
| 38 | + with: |
| 39 | + image: docker |
| 40 | + options: -v ${{ github.workspace }}:/work |
| 41 | + run: | |
| 42 | + echo "::set-output name=file-contents::`cat /work/someFile`" |
| 43 | + - name: Check if file contents match |
| 44 | + uses: actions/github-script@v3 |
| 45 | + with: |
| 46 | + script: | |
| 47 | + const fileContents = '${{ steps.run-docker.outputs.file-contents }}'; |
| 48 | + if (fileContents !== 'some text') { |
| 49 | + core.setFailed(`Unable to mount workspace volume`); |
| 50 | + } |
| 51 | + container-network-test: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + services: |
| 54 | + postgres: |
| 55 | + image: postgres |
| 56 | + env: |
| 57 | + POSTGRES_PASSWORD: test |
| 58 | + POSTGRES_USER: test |
| 59 | + POSTGRES_DB: test |
| 60 | + ports: |
| 61 | + - 5432:5432 |
| 62 | + options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v2 |
| 65 | + - name: Run docker action and test network connection |
| 66 | + uses: ./ |
| 67 | + with: |
| 68 | + image: postgres |
| 69 | + run: > |
| 70 | + pg_isready -d test -U test -h postgres -p ${{ job.services.postgres.ports[5432] }} |
| 71 | + options: > |
| 72 | + -e PGPASSWORD=test |
0 commit comments