Skip to content

Commit

Permalink
Merge branch 'develop' into aen_require_curl_jq
Browse files Browse the repository at this point in the history
  • Loading branch information
aednichols authored Jan 2, 2024
2 parents 6cd24a3 + e3a923f commit af1e287
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 42 deletions.
57 changes: 47 additions & 10 deletions .github/workflows/consumer_contract_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,25 @@ name: Consumer contract tests
# Consumer kicks off can-i-deploy on process to determine if changes can be promoted and used for deployment.
#
# NOTE: The publish-contracts workflow will use the latest commit of the branch that triggers this workflow to publish the unique consumer contract version to Pact Broker.

on:
pull_request:
branches:
- develop
paths-ignore:
- 'README.md'
push:
branches:
- develop
paths-ignore:
- 'README.md'
merge_group:
branches:
- develop

env:
PUBLISH_CONTRACTS_RUN_NAME: 'publish-contracts-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'
CAN_I_DEPLOY_RUN_NAME: 'can-i-deploy-${{ github.event.repository.name }}-${{ github.run_id }}-${{ github.run_attempt }}'

jobs:
init-github-context:
runs-on: ubuntu-latest
Expand All @@ -52,6 +59,23 @@ jobs:
steps:
- uses: actions/checkout@v3

# Construct a version string like `87-9c6c439`. Adapted from `chart_update_on_merge.yml`.
- name: Find Cromwell short SHA
run: |
set -e
echo "CROMWELL_SHORT_SHA=`git rev-parse --short $GITHUB_SHA`" >> $GITHUB_ENV
- name: Find Cromwell release number
run: |
set -e
previous_version=$(curl -X GET https://api.github.com/repos/broadinstitute/cromwell/releases/latest | jq .tag_name | xargs)
if ! [[ "${previous_version}" =~ ^[0-9][0-9]+$ ]]; then
exit 1
fi
echo "CROMWELL_NUMBER=$((previous_version + 1))" >> $GITHUB_ENV
- name: Save complete image ID
run: |
echo "CROMWELL_VERSION=`echo "$CROMWELL_NUMBER-$CROMWELL_SHORT_SHA"`" >> $GITHUB_ENV
- name: Extract branch
id: extract-branch
run: |
Expand All @@ -70,9 +94,9 @@ jobs:
fi
echo "CURRENT_BRANCH=${GITHUB_REF/refs\/heads\//""}" >> $GITHUB_ENV
echo "CURRENT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
echo "repo-branch=${GITHUB_REF/refs\/heads\//""}" >> $GITHUB_OUTPUT
echo "repo-version=${GITHUB_SHA}" >> $GITHUB_OUTPUT
echo "repo-version=${CROMWELL_VERSION}" >> $GITHUB_OUTPUT
echo "fork=${FORK}" >> $GITHUB_OUTPUT
- name: Is PR triggered by forked repo?
Expand All @@ -88,7 +112,7 @@ jobs:
echo "repo-version=${{ steps.extract-branch.outputs.repo-version }}"
echo "fork=${{ steps.extract-branch.outputs.fork }}"
cromwell-consumer-contract-tests:
cromwell-contract-tests:
runs-on: ubuntu-latest
needs: [init-github-context]
outputs:
Expand All @@ -109,35 +133,48 @@ jobs:
id: encode-pact
run: |
cd pact4s
NON_BREAKING_B64=$(cat target/pacts/cromwell-consumer-drshub-provider.json | base64 -w 0)
NON_BREAKING_B64=$(cat target/pacts/cromwell-drshub.json | base64 -w 0)
echo "pact-b64=${NON_BREAKING_B64}" >> $GITHUB_OUTPUT
# Prevent untrusted sources from using PRs to publish contracts
# since access to secrets is not allowed.
publish-contracts:
runs-on: ubuntu-latest
if: ${{ needs.init-github-context.outputs.fork == 'false' || needs.init-github-context.outputs.fork == ''}}
needs: [init-github-context, cromwell-consumer-contract-tests]
needs: [init-github-context, cromwell-contract-tests]
steps:
- name: Dispatch to terra-github-workflows
uses: broadinstitute/workflow-dispatch@v3
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.PUBLISH_CONTRACTS_RUN_NAME }}"
workflow: .github/workflows/publish-contracts.yaml
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ secrets.BROADBOT_GITHUB_TOKEN }} # github token for access to kick off a job in the private repo
inputs: '{ "pact-b64": "${{ needs.cromwell-consumer-contract-tests.outputs.pact-b64 }}", "repo-owner": "${{ github.repository_owner }}", "repo-name": "${{ github.event.repository.name }}", "repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}" }'
inputs: '{
"run-name": "${{ env.PUBLISH_CONTRACTS_RUN_NAME }}",
"pact-b64": "${{ needs.cromwell-contract-tests.outputs.pact-b64 }}",
"repo-owner": "${{ github.repository_owner }}",
"repo-name": "${{ github.event.repository.name }}",
"repo-branch": "${{ needs.init-github-context.outputs.repo-branch }}",
"release-tag": "${{ needs.init-github-context.outputs.repo-version }}"
}'

can-i-deploy:
runs-on: ubuntu-latest
if: ${{ needs.init-github-context.outputs.fork == 'false' || needs.init-github-context.outputs.fork == ''}}
needs: [ init-github-context, publish-contracts ]
steps:
- name: Dispatch to terra-github-workflows
uses: broadinstitute/workflow-dispatch@v3
uses: broadinstitute/workflow-dispatch@v4.0.0
with:
run-name: "${{ env.CAN_I_DEPLOY_RUN_NAME }}"
workflow: .github/workflows/can-i-deploy.yaml
repo: broadinstitute/terra-github-workflows
ref: refs/heads/main
token: ${{ secrets.BROADBOT_GITHUB_TOKEN }} # github token for access to kick off a job in the private repo
inputs: '{ "pacticipant": "cromwell-consumer", "version": "${{ needs.init-github-context.outputs.repo-version }}" }'
inputs: '{
"run-name": "${{ env.CAN_I_DEPLOY_RUN_NAME }}",
"pacticipant": "cromwell",
"version": "${{ needs.init-github-context.outputs.repo-version }}"
}'
2 changes: 1 addition & 1 deletion .github/workflows/scalafmt-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Scalafmt'
name: 'ScalaFmt Check'

# This GitHub Action runs the ScalaFmt linting tool on the entire codebase.
# It fails if any files are not formatted properly.
Expand Down
58 changes: 37 additions & 21 deletions .github/workflows/scalafmt-fix.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,64 @@
name: 'Scalafmt'
name: 'ScalaFmt Fix'

# This GitHub Action runs the ScalaFmt linting tool on the entire codebase.
# It will fix, commit, and push linted code.
# It will only run when someone comments "scalafmt" on a PR.

run-name: ${{ format('ScalaFmt Fix on {0}', github.ref_name) }}
run-name: ScalaFmt Fix

on:
workflow_dispatch:
issue_comment:
types:
- created
workflow_dispatch:
branch_name:
description: 'Branch to run ScalaFmt against'
required: true
pull_request_target:
types:
- opened
- synchronize

jobs:
run-scalafmt-fix:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.target-branch }}
- uses: ./.github/set_up_cromwell_action
with:
cromwell_repo_token: ${{ secrets.BROADBOT_GITHUB_TOKEN }}
- name: Determine Target Branch
id: determine-branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "::set-output name=target_branch::${{ inputs.branch_name }}"
else
echo "::set-output name=target_branch::${{ github.event.pull_request.head.ref }}"
fi
shell: bash
env:
inputs.branch_name: ${{ inputs.branch_name }}
- name: Check for ScalaFmt Comment
id: check-comment
run: |
if [[ "${{ github.event_name }}" == "issue_comment" && "${{ github.event.comment.body }}" == *"scalafmt"* ]]; then
echo "::set-output name=comment-triggered::true"
echo "::set-output name=comment-author-email::${{ github.event.comment.user.login }}@users.noreply.github.com"
echo "::set-output name=comment-author-name::${{ github.event.comment.user.login }}"
else
echo "::set-output name=comment-triggered::false"
fi
shell: bash
- name: Run ScalaFmt
- uses: actions/checkout@v3 # checkout the cromwell repo
with:
ref: ${{ inputs.target-branch }}
- uses: ./.github/set_up_cromwell_action
with:
cromwell_repo_token: ${{ secrets.BROADBOT_GITHUB_TOKEN }}
- name: Run ScalaFmt Fixup
if: steps.check-comment.outputs.comment-triggered == 'true' || github.event_name == 'workflow_dispatch'
env:
BROADBOT_GITHUB_TOKEN: ${{ secrets.BROADBOT_GITHUB_TOKEN }}
run: |
if [[ ${{ steps.check-comment.outputs.comment-triggered }} == true ]]; then
echo "PR Comment Detected. Formatting, committing, and pushing formatted scala code."
sbt scalaFmtAll
git config --global user.email "${{ steps.check-comment.outputs.comment-author-email }}"
git config --global user.name "${{ steps.check-comment.outputs.comment-author-name }}"
git add .
git commit -m "Auto-format code with ScalaFmt"
git push origin ${{ github.ref }}
fi
sbt scalafmtAll
git config --global user.email "[email protected]"
git config --global user.name "Broad Bot"
git add .
git commit -m "ScalaFmt fixup via Broad Bot"
git push origin ${{ steps.determine-branch.outputs.target_branch }}
working-directory: ${{ github.workspace }}
3 changes: 1 addition & 2 deletions pact4s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ docker run --rm -v $PWD:/working \
```

The generated contracts can be found in the `./target/pacts` folder
- `cromwell-consumer-drshub-provider.json`
- `cromwell-consumer-fake-provider.json`
- `cromwell-drshub.json`

Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ class DrsHubClientSpec extends AnyFlatSpec with Matchers with RequestResponsePac
}.build

val consumerPactBuilder: ConsumerPactBuilder = ConsumerPactBuilder
.consumer("cromwell-consumer")
.consumer("cromwell")

val pactProvider: PactDslWithProvider = consumerPactBuilder
.hasPactWith("drshub-provider")
.hasPactWith("drshub")

var pactDslResponse: PactDslResponse = buildInteraction(
pactProvider,
Expand All @@ -134,7 +134,7 @@ class DrsHubClientSpec extends AnyFlatSpec with Matchers with RequestResponsePac
uponReceiving = "Request to resolve drs url",
method = "POST",
path = "/api/v4/drs/resolve",
requestHeaders = Seq("Content-type" -> "application/json"),
requestHeaders = Seq("Content-Type" -> "application/json"),
requestBody = resourceRequestDsl,
status = 200,
responseHeaders = Seq(),
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ object Dependencies {
"org.lz4" % "lz4-java" % lz4JavaV
)
val scalaTest = "org.scalatest" %% "scalatest" % scalatestV

val testDependencies: List[ModuleID] = List(
"org.scalatest" %% "scalatest" % scalatestV,
// Use mockito Java DSL directly instead of the numerous and often hard to keep updated Scala DSLs.
Expand Down
9 changes: 5 additions & 4 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ object Settings {
organization := "org.broadinstitute",
scalaVersion := ScalaVersion,
resolvers ++= additionalResolvers,
// Don't run tasks in parallel, especially helps in low CPU environments like Travis
Global / parallelExecution := false,
Global / parallelExecution := true,
// Seems to cause race conditions in tests, that are not pertinent to what's being tested
Test / parallelExecution := false,
Global / concurrentRestrictions ++= List(
// Don't run any other tasks while running tests, especially helps in low CPU environments like Travis
// Don't run any other tasks while running tests
Tags.exclusive(Tags.Test),
// Only run tests on one sub-project at a time, especially helps in low CPU environments like Travis
// Only run tests on one sub-project at a time
Tags.limit(Tags.Test, 1)
),
dependencyOverrides ++= cromwellDependencyOverrides,
Expand Down

0 comments on commit af1e287

Please sign in to comment.