Skip to content

Commit

Permalink
Merge pull request #11 from ConseilsTI/v1.0.8
Browse files Browse the repository at this point in the history
v1.0.8
  • Loading branch information
benyboy84 authored Mar 25, 2024
2 parents 257322c + cfce34d commit a758db4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@ jobs:
VALIDATE_MARKDOWN: true
VALIDATE_TERRAFORM_TFLINT: true
VALIDATE_YAML: true
# Exclude README.md file because it is generated
FILTER_REGEX_EXCLUDE: README.md
72 changes: 72 additions & 0 deletions .github/workflows/module_release.yml
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
}
1 change: 1 addition & 0 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ permissions:
jobs:
tag:
name: Tag version
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down

0 comments on commit a758db4

Please sign in to comment.