diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..a25a05bf --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,71 @@ +name: Run tests and push Docker image on success + +"on": + push: + branches: [main] + pull_request: + release: + types: [published] + +permissions: {} + +jobs: + test-and-push: + runs-on: [ubuntu] + permissions: + contents: write + id-token: write + packages: write + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up Docker Context for Buildx + id: buildx-context + run: docker context use builders || docker context create builders + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + with: + version: latest + endpoint: builders + + - name: Log in to GitHub Container Registry + id: ghcr_login + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Prep Tags + id: prep + run: | + TAG=noop + if [[ $GITHUB_REF == refs/tags/* ]]; then + TAG=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/pull/* ]]; then + TAG="sha-${GITHUB_SHA::8}" + elif [ "${{ github.event_name }}" = "push" ]; then + TAG="sha-${GITHUB_SHA::8}" + fi + echo ::set-output name=tag::${TAG} + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + + - name: Build image + run: make build + env: + NETWORK: host + IMAGE_TAG: ${{ steps.prep.outputs.tag }} + + - name: Run Python tests (docker-compose) + run: make clean && make test + env: + NETWORK: default + IMAGE_TAG: ${{ steps.prep.outputs.tag }} + + - name: Push image + run: make push + env: + IMAGE_TAG: ${{ steps.prep.outputs.tag }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7601b2f..17d2587e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,68 +1,68 @@ ---- -name: 🧪 Test +# --- +# name: 🧪 Test -on: - pull_request: - branches: - - main +# on: +# pull_request: +# branches: +# - main -permissions: {} +# permissions: {} -jobs: - test: - name: Test - runs-on: ubuntu-latest - permissions: - contents: write - id-token: write - packages: write - steps: - - name: Checkout - id: checkout - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 +# jobs: +# test: +# name: Test +# runs-on: ubuntu-latest +# permissions: +# contents: write +# id-token: write +# packages: write +# steps: +# - name: Checkout +# id: checkout +# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - # - name: Set Up Container Structure Test - # id: setup_container_structure_test - # uses: ministryofjustice/github-actions/setup-container-structure-test@ccf9e3a4a828df1ec741f6c8e6ed9d0acaef3490 # v18.5.0 +# # - name: Set Up Container Structure Test +# # id: setup_container_structure_test +# # uses: ministryofjustice/github-actions/setup-container-structure-test@ccf9e3a4a828df1ec741f6c8e6ed9d0acaef3490 # v18.5.0 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 +# - name: Set up Docker Buildx +# uses: docker/setup-buildx-action@v2 - - name: Install Docker Compose - id: docker-compose - shell: bash - env: - IMAGE_TAG: ${{ github.sha }} - run: | - sudo curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose - docker-compose --version +# - name: Install Docker Compose +# id: docker-compose +# shell: bash +# env: +# IMAGE_TAG: ${{ github.sha }} +# run: | +# sudo curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +# sudo chmod +x /usr/local/bin/docker-compose +# docker-compose --version - - name: Build with Docker Compose - id: build - shell: bash - env: - IMAGE_TAG: ${{ github.sha }} - run: | - make build +# - name: Build with Docker Compose +# id: build +# shell: bash +# env: +# IMAGE_TAG: ${{ github.sha }} +# run: | +# make build - - name: Log in to GitHub Container Registry - id: ghcr_login - uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} +# - name: Log in to GitHub Container Registry +# id: ghcr_login +# uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 +# with: +# registry: ghcr.io +# username: ${{ github.actor }} +# password: ${{ secrets.GITHUB_TOKEN }} - - name: Push - id: push - env: - IMAGE_NAME: ghcr.io/ministryofjustice/analytics-platform-control-panel - run: | - docker push $IMAGE_NAME:${{ github.sha }} +# - name: Push +# id: push +# env: +# IMAGE_NAME: ghcr.io/ministryofjustice/analytics-platform-control-panel +# run: | +# docker push $IMAGE_NAME:${{ github.sha }} - - name: Run tests - env: - IMAGE_TAG: ${{ github.sha }} - run: | - make test-python \ No newline at end of file +# - name: Run tests +# env: +# IMAGE_TAG: ${{ github.sha }} +# run: | +# make test-python \ No newline at end of file