-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ConseilsTI/v1.0.8
v1.0.8
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# This workflow runs after `Tag version` or on `release` `published`. | ||
# | ||
# `Publish module version` runs command-line to make API to publish a new version of the module. | ||
# Documentation | ||
# - https://developer.hashicorp.com/terraform/cloud-docs/api-docs/private-registry/modules#create-a-module-version | ||
|
||
name: Publish module version | ||
|
||
on: # yamllint disable-line rule:truthy | ||
release: | ||
types: [published] | ||
workflow_run: | ||
workflows: ["Tag version"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
tag: | ||
name: Publish module version | ||
runs-on: ubuntu-latest | ||
env: | ||
TFC_ORGANIZATION: "ConseilsTI" | ||
TFC_API_TOKEN: ${{ secrets.TFC_API_TOKEN }} | ||
steps: | ||
|
||
- name: Publish module version | ||
env: | ||
EVENT_CONTEXT: ${{ toJson(github.event) }} | ||
run: | | ||
echo "INFO | Build required variables." | ||
tfc_api_url="https://app.terraform.io/api/v2" | ||
auth_header="Authorization: Bearer ${TFC_API_TOKEN}" | ||
content_header="Content-Type: application/vnd.api+json" | ||
echo "INFO | Get release version." | ||
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then | ||
version=$(echo "${EVENT_CONTEXT}" | jq ".workflow_run.head_branch" | sed 's|\"||g') | ||
elif [[ "${{ github.event_name }}" == "release" ]]; then | ||
version="${{ github.ref_name }}" | ||
else | ||
echo "ERROR | Event name is not \"workflow_run\" or \"release\"." | ||
exit 1 | ||
fi | ||
version="${version//v/}" | ||
commit_sha="${{ github.sha }}" | ||
echo "INFO | Version: ${version}" | ||
echo "INFO | SHA: ${commit_sha}" | ||
echo "INFO | Build JSON payload." | ||
json_string='{"data": {"type": "registry-module-versions","attributes": {"version": "'"${version}"'","commit_sha": "'"${commit_sha}"'"} } }' | ||
json_payload=$(echo "${json_string}" | jq) | ||
echo "INFO | Get Terraform module provider and name." | ||
repository_name=$(echo "${EVENT_CONTEXT}" | jq ".repository.name" | sed 's|\"||g') | ||
echo "INFO | GitHub repository name: ${repository_name}" | ||
repository_name_array=$(echo "${repository_name}" | tr "-" " ") | ||
read -r -a array <<< "${repository_name_array}" | ||
module_provider="${array[1]}" | ||
echo "INFO | Module provider: ${module_provider}" | ||
module_name=$(echo "${repository_name}" | sed -n -e "s/^.*-${module_provider}-//p" ) | ||
echo "INFO | Module name: ${module_name}" | ||
echo "INFO | Run API call to publish a new version." | ||
{ | ||
run=$(curl --request POST --url "${tfc_api_url}/organizations/${TFC_ORGANIZATION}/registry-modules/private/${TFC_ORGANIZATION}/${module_name}/${module_provider}/versions" \ | ||
--header "${auth_header}" --header "${content_header}" --data "${json_payload}") | ||
if ! [[ "${run}" =~ "{\"data\":" ]]; then | ||
echo "ERROR | Unable to published new module version." | ||
echo "${run}" | ||
exit 1 | ||
fi | ||
} || | ||
{ | ||
echo "ERROR | Unable to published new module version." | ||
exit 1 | ||
} |
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