Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Align base env vars #10

Merged
merged 4 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Actions Release

on:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [16.x]
action: [
can-i-deploy,
create-version-tag,
publish-pact-files,
# publish-provider-contract,
publish-provider-contract-legacy,
record-deployment,
]

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x for ${{ matrix.action }}
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "npm"
cache-dependency-path: ${{ matrix.action }}/package-lock.json
- run: npm ci
working-directory: ${{ matrix.action }}
- run: npm run test:unit
name: test ${{ matrix.action }}
working-directory: ${{ matrix.action }}

release:
needs: test
runs-on: ubuntu-latest
steps:
- uses: K-Phoen/semver-release-action@master
with:
release_branch: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124 changes: 124 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Actions test

on:
push:
pull_request:

env:
version: ${{ github.sha }}
environment: production
application_name: "actions-consumer"
PACT_BROKER_BASE_URL: https://testdemo.pactflow.io
PACT_BROKER_TOKEN: ${{ secrets.PACTFLOW_TOKEN_FOR_CI_CD_WORKSHOP }}

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [16.x]
action: [
can-i-deploy,
create-version-tag,
publish-pact-files,
# publish-provider-contract,
publish-provider-contract-legacy,
record-deployment,
]

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x for ${{ matrix.action }}
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "npm"
cache-dependency-path: ${{ matrix.action }}/package-lock.json
- run: npm ci
working-directory: ${{ matrix.action }}
- run: npm run test:unit
name: test ${{ matrix.action }}
working-directory: ${{ matrix.action }}

pact-publish-oas-action:
# needs: test
runs-on: ubuntu-latest
steps:
# MANDATORY: Must use 'checkout' first
- uses: actions/checkout@v2
- name: Publish provider contract on passing test run
if: success()
uses: ./publish-provider-contract
env:
application_name: actions-provider
oas_file: test/products.yml
results_file: test/report.md
- name: Publish provider contract on failing test run
# ensure we publish results even if the tests fail
if: failure()
uses: ./publish-provider-contract
env:
application_name: actions-provider
oas_file: test/products.yml
results_file: test/report.md
# ensure we set the EXIT_CODE to ensure we upload a failing self-verification result
EXIT_CODE: 1

pact-can-i-deploy-provider:
needs: pact-publish-oas-action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./can-i-deploy
env:
to_environment: ${{ env.environment }}
application_name: actions-provider

pact-record-deployment-provider:
needs: pact-can-i-deploy-provider
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./record-deployment
env:
environment: ${{ env.environment }}
application_name: actions-provider

publish-pact-files:
needs: pact-record-deployment-provider
runs-on: ubuntu-latest
steps:
# MANDATORY: Must use 'checkout' first
- uses: actions/checkout@v2
- uses: ./publish-pact-files
env:
pactfiles: test/pact.json

pact-can-i-deploy-consumer:
needs: publish-pact-files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./can-i-deploy
env:
to_environment: ${{ env.environment }}

pact-record-deployment-consumer:
needs: pact-can-i-deploy-consumer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./record-deployment
env:
environment: ${{ env.environment }}

pact-create-version-tag:
needs: pact-record-deployment-consumer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./create-version-tag
env:
tag: ${{ env.environment }}
3 changes: 1 addition & 2 deletions can-i-deploy/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package-lock.json
node_modules/
node_modules/
6 changes: 3 additions & 3 deletions can-i-deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

Checks you can deploy based on target environment or tag

Check https://docs.pact.io/pact_broker/can_i_deploy for an overview of can-i-deploy
Check https://docs.pact.io/pact_broker/can_i_deploy for an overview of can-i-deploy

## Example

```yml
# (This just saves defining these multiple times for different pact jobs)
env:
application_name: "my-consumer-app" # The pacticipant name of which to check if it safe to deploy
pact_broker: ${{ secrets.PACT_BROKER }} # The base URL of the Pact Broker
pact_broker_token: ${{ secrets.PACT_BROKER_TOKEN }} # Pactflow Broker API Read/Write token
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }} # The base URL of the Pact Broker
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} # Pactflow Broker API Read/Write token

jobs:
pact-can-i-deploy:
Expand Down
4 changes: 2 additions & 2 deletions can-i-deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ branding:
icon: "check"
color: "green"
inputs:
pact_broker:
PACT_BROKER_BASE_URL:
description: "The url of your pact broker"
required: true
pact_broker_token:
PACT_BROKER_TOKEN:
description: "Your pact broker token"
required: true
application_name:
Expand Down
36 changes: 18 additions & 18 deletions can-i-deploy/canideployTo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ VERSION="--latest"
[ "$latest" != "" ] && VERSION="--latest $latest"

MISSING=()
[ ! "$pact_broker" ] && MISSING+=("pact_broker")
[ ! "$pact_broker_token" ] && MISSING+=("pact_broker_token")
[ ! "$PACT_BROKER_BASE_URL" ] && MISSING+=("PACT_BROKER_BASE_URL")
[ ! "$PACT_BROKER_TOKEN" ] && MISSING+=("PACT_BROKER_TOKEN")
[ ! "$application_name" ] && MISSING+=("application_name")

if [ ${#MISSING[@]} -gt 0 ]; then
Expand All @@ -22,33 +22,33 @@ fi

COMMAND=
if [ -z "$to" ] || [ -z "$to_environment" ]; then
if [ -z "$to" ] && [ "$to_environment" ]; then
echo "You set to_environment"
COMMAND="--to-environment $to_environment"
elif [ -z "$to_environment" ] && [ "$to" ]; then
echo "You set to"
COMMAND="--to $to"
else
echo "you need to set to, or to_environment"
exit 1
fi
else
echo "you can only set to, or to_environment"
if [ -z "$to" ] && [ "$to_environment" ]; then
echo "You set to_environment"
COMMAND="--to-environment $to_environment"
elif [ -z "$to_environment" ] && [ "$to" ]; then
echo "You set to"
COMMAND="--to $to"
else
echo "you need to set to, or to_environment"
exit 1
fi
else
echo "you can only set to, or to_environment"
exit 1
fi

echo $COMMAND

echo "
pact_broker: '$pact_broker'
pact_broker_token: '$pact_broker_token'
PACT_BROKER_BASE_URL: '$PACT_BROKER_BASE_URL'
PACT_BROKER_TOKEN: '$PACT_BROKER_TOKEN'
application_name: '$application_name'
VERSION: '$VERSION'
to: $to"

docker run --rm \
-e PACT_BROKER_BASE_URL=$pact_broker \
-e PACT_BROKER_TOKEN=$pact_broker_token \
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \
pactfoundation/pact-cli:latest \
broker can-i-deploy \
--pacticipant "$application_name" \
Expand Down
Loading