|
| 1 | +name: ci-build |
| 2 | + |
| 3 | +# Run this workflow every time a new commit pushed to your repository |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + - stable/1.0.x |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + pull_request: |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + IMAGE_NAME: vngr/gemma-brc |
| 16 | + DJANGO_SETTINGS_MODULE: brc.conf.jenkins |
| 17 | + SECRET_KEY: dummy |
| 18 | + DB_USER: postgres |
| 19 | + DB_PASSWORD: '' |
| 20 | + DEPLOYMENT: brc |
| 21 | + |
| 22 | +jobs: |
| 23 | + tests: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + strategy: |
| 26 | + matrix: |
| 27 | + postgres: ['10', '11', '12'] |
| 28 | + |
| 29 | + name: Tests (PG ${{ matrix.postgres }}) |
| 30 | + |
| 31 | + services: |
| 32 | + postgres: |
| 33 | + image: postgres:${{ matrix.postgres }} |
| 34 | + env: |
| 35 | + POSTGRES_HOST_AUTH_METHOD: trust |
| 36 | + ports: |
| 37 | + - 5432:5432 |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v2 |
| 41 | + - uses: actions/setup-python@v2 |
| 42 | + with: |
| 43 | + python-version: '3.6' |
| 44 | + - uses: actions/setup-node@v2-beta |
| 45 | + with: |
| 46 | + node-version: '12' |
| 47 | + |
| 48 | + # - name: Install system packages |
| 49 | + # run: sudo apt-get install libgdal-dev gdal-bin |
| 50 | + |
| 51 | + - name: Install dependencies |
| 52 | + run: pip install -r requirements/jenkins.txt codecov |
| 53 | + |
| 54 | + - name: Build frontend |
| 55 | + run: | |
| 56 | + npm ci |
| 57 | + npm run build |
| 58 | + - name: Run tests |
| 59 | + run: | |
| 60 | + python src/manage.py collectstatic --noinput --link |
| 61 | + coverage run src/manage.py test src |
| 62 | +
|
| 63 | + - name: Publish coverage report |
| 64 | + uses: codecov/codecov-action@v1 |
| 65 | + |
| 66 | + docker: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + name: Docker image build |
| 69 | + |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v2 |
| 72 | + - name: Determine tag/commit hash |
| 73 | + id: vars |
| 74 | + run: | |
| 75 | + # Strip git ref prefix from version |
| 76 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 77 | + # Strip "v" prefix from tag name (if present at all) |
| 78 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 79 | + # Use Docker `latest` tag convention |
| 80 | + [ "$VERSION" == "master" ] && VERSION=latest |
| 81 | + echo ::set-output name=tag::${VERSION} |
| 82 | + echo ::set-output name=git_hash::${GITHUB_SHA} |
| 83 | + - name: Build the Docker image |
| 84 | + run: | |
| 85 | + docker build . \ |
| 86 | + --build-arg COMMIT_HASH=${{ steps.vars.outputs.git_hash }} |
| 87 | + # - run: docker image save -o image.tar $IMAGE_NAME:${{ steps.vars.outputs.tag }} |
| 88 | + # - name: Store image artifact |
| 89 | + # uses: actions/upload-artifact@v2 |
| 90 | + # with: |
| 91 | + # name: docker-image |
| 92 | + # path: image.tar |
| 93 | + # retention-days: 1 |
| 94 | + |
| 95 | + publish: |
| 96 | + needs: |
| 97 | + - tests |
| 98 | + - docker |
| 99 | + |
| 100 | + name: Push Docker image |
| 101 | + runs-on: ubuntu-latest |
| 102 | + if: github.event_name == 'push' # exclude PRs/forks |
| 103 | + |
| 104 | + steps: |
| 105 | + - uses: actions/checkout@v2 |
| 106 | + # - name: Download built image |
| 107 | + # uses: actions/download-artifact@v2 |
| 108 | + # with: |
| 109 | + # name: docker-image |
| 110 | + - name: Publish latest image |
| 111 | + env: # Or as an environment variable |
| 112 | + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} |
| 113 | + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} |
| 114 | + DEPLOY_BOT_TOKEN: ${{ secrets.DEPLOY_BOT_TOKEN }} |
| 115 | + run: | |
| 116 | + BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 117 | + if [ "$BRANCH" == "master" ]; then |
| 118 | + bash bin/cicd.sh latest no |
| 119 | + fi |
| 120 | +
|
| 121 | + - name: Publish tagged image |
| 122 | + env: # Or as an environment variable |
| 123 | + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} |
| 124 | + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} |
| 125 | + DEPLOY_BOT_TOKEN: ${{ secrets.DEPLOY_BOT_TOKEN }} |
| 126 | + run: | |
| 127 | + TAG=$(git name-rev --tags --name-only $(git rev-parse HEAD)) |
| 128 | + if [ "$TAG" != "undefined" ]; then |
| 129 | + bash bin/cicd.sh $TAG yes |
| 130 | + fi |
| 131 | +
|
| 132 | + # - name: Determine tag/commit hash |
| 133 | + # id: vars |
| 134 | + # run: | |
| 135 | + # # Strip git ref prefix from version |
| 136 | + # VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 137 | + # # Strip "v" prefix from tag name (if present at all) |
| 138 | + # [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 139 | + # # Use Docker `latest` tag convention |
| 140 | + # [ "$VERSION" == "develop" ] && VERSION=latest |
| 141 | + # echo ::set-output name=tag::${VERSION} |
| 142 | + # - name: Load image |
| 143 | + # run: | |
| 144 | + # docker image load -i image.tar |
| 145 | + # - name: Log into registry |
| 146 | + # run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin |
| 147 | + |
| 148 | + # - name: Push the Docker image |
| 149 | + # run: docker push $IMAGE_NAME:${{ steps.vars.outputs.tag }} |
0 commit comments