healthcheck feature #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: consumer-pipeline | |
on: | |
# workflow_dispatch: | |
pull_request: | |
branches: | |
- master | |
env: | |
PACT_BROKER_BASE_URL: https://danrusu.pactflow.io | |
PACT_BROKER_TOKEN: ${{secrets.PACT_BROKER_TOKEN}} | |
PACT_CONSUMER: pact-consumer-poc | |
PACT_PROVIDER: pact-provider-poc | |
API_BASE_URL: http://localhost:4000 | |
GIT_COMMIT: ${{github.sha}} | |
GIT_REF: ${{github.head_ref}} # this works only for PRs | |
DEPLOY_ENV: test # set this dynamically | |
ACTIONS_ALLOW_UNSECURE_COMMANDS: true # to be able use ::set-env | |
jobs: | |
unit-tests: | |
name: Unit tests (fake) | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "Successfull unit tests" | |
contract-tests: | |
name: Contract tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
run: npm install | |
- name: Run contract tests | |
run: npm run test:pact | |
- name: Save short sha to ENV | |
run: | | |
echo ::set-env name=SHORT_SHA::$(echo ${GIT_COMMIT:0:7}) | |
- name: Save branch name to ENV | |
run: | | |
echo ::set-env name=BRANCH::$(echo $GIT_REF | rev | cut -d'/' -f 1 | rev) | |
- name: Publish pacts between ${{env.PACT_CONSUMER}} and ${{env.PACT_PROVIDER}} | |
run: | | |
docker run \ | |
-w /opt/pact \ | |
-v ${PWD}/pact/pacts:/opt/pact \ | |
-e PACT_BROKER_BASE_URL=${{env.PACT_BROKER_BASE_URL}} \ | |
-e PACT_BROKER_TOKEN=${{env.PACT_BROKER_TOKEN}} \ | |
pactfoundation/pact-cli:latest publish . \ | |
--consumer-app-version ${{env.SHORT_SHA}} \ | |
--branch ${{env.BRANCH}} | |
e2e-tests: | |
name: E2E tests (fake) | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "Successfull e2e tests" | |
can-i-deploy: | |
name: Can I deploy | |
needs: contract-tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Save short sha to ENV | |
run: | | |
echo ::set-env name=SHORT_SHA::$(echo ${GIT_COMMIT:0:7}) | |
- run: | | |
docker run \ | |
-e PACT_BROKER_BASE_URL=${{env.PACT_BROKER_BASE_URL}} \ | |
-e PACT_BROKER_TOKEN=${{env.PACT_BROKER_TOKEN}} \ | |
pactfoundation/pact-cli:latest pact-broker can-i-deploy \ | |
--pacticipant ${{env.PACT_CONSUMER}} \ | |
--version ${{env.SHORT_SHA}} \ | |
--to-environment ${{env.DEPLOY_ENV}} | |
deploy: | |
name: Deploy (fake) | |
needs: | |
- unit-tests | |
- contract-tests | |
- e2e-tests | |
- can-i-deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Save short sha to ENV | |
run: | | |
echo ::set-env name=SHORT_SHA::$(echo ${GIT_COMMIT:0:7}) | |
- run: echo "Deploy ${{env.PACT_CONSUMER}} with version ${{env.SHORT_SHA}} to '${{env.DEPLOY_ENV}}' environment" | |
record-deployment: | |
name: Record Deployment | |
needs: deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Save short sha to ENV | |
run: | | |
echo ::set-env name=SHORT_SHA::$(echo ${GIT_COMMIT:0:7}) | |
- name: Record deployment of ${{env.PACT_CONSUMER}} with version ${{env.SHORT_SHA}} to '${{env.DEPLOY_ENV}}' environment | |
run: | | |
docker run \ | |
-e PACT_BROKER_BASE_URL=${{env.PACT_BROKER_BASE_URL}} \ | |
-e PACT_BROKER_TOKEN=${{env.PACT_BROKER_TOKEN}} \ | |
pactfoundation/pact-cli:latest pact-broker record-deployment \ | |
--pacticipant ${{env.PACT_CONSUMER}} \ | |
--version ${{env.SHORT_SHA}} \ | |
--environment ${{env.DEPLOY_ENV}} |