Skip to content

Commit

Permalink
Merge pull request #32 from tienvx/feat-create-or-update-version
Browse files Browse the repository at this point in the history
feat: Create or update version
  • Loading branch information
YOU54F authored Jul 28, 2023
2 parents f04685e + 2e66c0b commit e94e130
Show file tree
Hide file tree
Showing 11 changed files with 5,737 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
# publish-provider-contract,
publish-provider-contract-legacy,
record-deployment,
create-or-update-version,
]

steps:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
# publish-provider-contract,
publish-provider-contract-legacy,
record-deployment,
create-or-update-version,
]

steps:
Expand Down Expand Up @@ -122,3 +123,10 @@ jobs:
- uses: ./create-version-tag
env:
tag: ${{ env.environment }}

pact-create-or-update-version:
needs: pact-record-deployment-consumer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./create-or-update-version
1 change: 1 addition & 0 deletions create-or-update-version/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
21 changes: 21 additions & 0 deletions create-or-update-version/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Tien Vo Xuan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions create-or-update-version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# create-or-update-version action

Create or update pacticipant version by version number

## Example

```yml
# (This just saves defining these multiple times for different pact jobs)
env:
version: "1.2.3"
application_name: "my-app"
PACT_BROKER_BASE_URL: ${{ secrets.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}

jobs:
create-or-update-version:
runs-on: ubuntu-latest
steps:
# MANDATORY: Must use 'checkout' first
- uses: actions/checkout@v2
- uses: pactflow/actions/[email protected]
```
23 changes: 23 additions & 0 deletions create-or-update-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "create-or-update-version"
description: "Create or update pacticipant version by version number"
branding:
icon: "check"
color: "green"
inputs:
PACT_BROKER_BASE_URL:
description: "The url of your pact broker"
required: true
PACT_BROKER_TOKEN:
description: "Your pact broker token"
required: true
application_name:
description: "The name of your application (usually project name)"
required: true
version:
description: "The version of your application (usually commit sha)"
required: true
runs:
using: "composite"
steps:
- run: ${{ github.action_path }}/createOrUpdateVersion.sh
shell: bash
32 changes: 32 additions & 0 deletions create-or-update-version/createOrUpdateVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

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

if [ ${#MISSING[@]} -gt 0 ]; then
echo "ERROR: The following environment variables are not set:"
printf '\t%s\n' "${MISSING[@]}"
exit 1
fi

branch=$(git rev-parse --abbrev-ref HEAD)

echo "
PACT_BROKER_BASE_URL: '$PACT_BROKER_BASE_URL'
PACT_BROKER_TOKEN: '$PACT_BROKER_TOKEN'
version: '$version'
application_name: '$application_name'
branch: '$branch'
"

docker run --rm \
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \
pactfoundation/pact-cli:latest \
broker create-or-update-version \
--pacticipant "$application_name" \
--version $version \
--branch $branch
Loading

0 comments on commit e94e130

Please sign in to comment.