fix pull errors #6
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: docker compose build and run | |
on: | |
workflow_call: | |
inputs: | |
application-name: | |
required: true | |
type: string | |
tag: | |
required: false | |
type: string | |
default: ${{ github.event.pull_request.head.sha || github.sha }} | |
code_coverage: | |
required: false | |
type: boolean | |
default: false | |
algolia_index: | |
required: false | |
type: string | |
default: null | |
artifacts_path: | |
required: false | |
type: string | |
default: null | |
cmd: | |
required: true | |
type: string | |
secrets: | |
dockerhub_user: | |
required: true | |
dockerhub_pass: | |
required: true | |
env: | |
TAG: ${{ inputs.tag }} | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
# See https://github.com/actions/runner/issues/409 - there is still no conditional operator | |
ALGOLIA_SUPPLIERS_INDEX_NAME: ${{ inputs.algolia_index && format('ci_{0}_{1}_{2}_supps', inputs.tag, github.run_number, inputs.algolia_index) || '' }} | |
ALGOLIA_MOMENTS_INDEX_NAME: ${{ inputs.algolia_index && format('ci_{0}_{1}_{2}_momes', inputs.tag, github.run_number, inputs.algolia_index) || '' }} | |
ALGOLIA_APPLICATION: ${{ inputs.algolia_index && secrets.ALGOLIA_APPLICATION || '' }} | |
ALGOLIA_SEARCH_API_KEY: ${{ inputs.algolia_index && secrets.ALGOLIA_SEARCH_API_KEY || '' }} | |
ALGOLIA_WRITE_API_KEY: ${{ inputs.algolia_index && secrets.ALGOLIA_WRITE_API_KEY || '' }} | |
jobs: | |
compose_run: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v1 | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
- name: Log in to Docker Hub | |
run: | | |
docker login -u ${{ secrets.dockerhub_user }} -p ${{ secrets.dockerhub_pass }} | |
- name: Compose up | |
uses: konvenit/workflowator/.github/actions/compose | |
with: | |
application-name: ${{ inputs.application-name }} | |
- name: Create Algolia index | |
if: ${{ inputs.algolia_index }} | |
run: | | |
docker compose -f docker-compose.test.yml exec -T ${{ inputs.application-name }} bundle exec rake algolia:create:all | |
- name: Run command | |
if: ${{ !inputs.code_coverage }} | |
run: | | |
docker compose -f docker-compose.test.yml exec -T ${{ inputs.application-name }} ${{ inputs.cmd}} | |
- name: Run command with code coverage | |
if: ${{ inputs.code_coverage }} | |
run: | | |
# Could we download that file, review it, and then use that - approved by us - local copy? | |
ci_env=`bash <(curl -s https://codecov.io/env)` | |
docker compose -f docker-compose.test.yml exec -T -e CI=true -e CODECOVERAGE=true $ci_env ${{ inputs.application-name }} ${{ inputs.cmd}} | |
- name: upload artifact | |
# uploads only if run failed | |
if: ${{ failure() && inputs.artifacts_path }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: upload artifacts | |
path: ${{ inputs.artifacts_path }} | |
- name: Remove Algolia index (flaky!) | |
if: inputs.algolia_index && always() | |
run: | | |
docker compose -f docker-compose.test.yml exec -T ${{ inputs.application-name }} bundle exec rake algolia:remove:all || true | |
- name: Stop containers | |
if: always() | |
run: docker compose -f docker-compose.test.yml down |