Skip to content

Commit 5a51973

Browse files
committed
test
1 parent 5b7e8ef commit 5a51973

File tree

3 files changed

+138
-43
lines changed

3 files changed

+138
-43
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
trap cleanup SIGINT SIGTERM ERR EXIT
5+
6+
temp_dir=$(mktemp -d)
7+
8+
cleanup() {
9+
trap - SIGINT SIGTERM ERR EXIT
10+
if [[ "${no_clean-}" == "yes" ]]; then
11+
echo -e "\nSkipping cleanup"
12+
else
13+
rm -rf "${temp_dir}"
14+
fi
15+
}
16+
17+
show_usage() {
18+
cat << EOF
19+
Usage: $(basename "$0") [OPTIONS]
20+
21+
Release a Terraform module by packaging, publishing, and tagging.
22+
23+
Options:
24+
-p, --publish Publish the module to Cloudsmith repository
25+
-t, --tag-push Create and push a Git tag for the release
26+
-m, --module-path Path to the module directory (required)
27+
-n, --no-clean Skip cleanup of temporary files
28+
-h, --help Show this help message
29+
30+
Example:
31+
$(basename "$0") -m modules/my-module -p -t
32+
EOF
33+
}
34+
35+
module_publish=no
36+
tag_push=no
37+
module_path=""
38+
39+
while :; do
40+
case "${1-}" in
41+
-h|--help)
42+
show_usage
43+
exit 0
44+
;;
45+
-p|--publish)
46+
module_publish=yes
47+
;;
48+
-t|--tag-push)
49+
tag_push=yes
50+
;;
51+
-m|--module-path)
52+
module_path="${2-}"
53+
shift
54+
;;
55+
-n|--no-clean)
56+
no_clean=yes
57+
;;
58+
*)
59+
break
60+
;;
61+
esac
62+
shift
63+
done
64+
65+
if [[ -z "$module_path" ]]; then
66+
echo "Module path is required"
67+
exit 1
68+
fi
69+
70+
if ! [[ -f "$module_path/.module.toml" ]]; then
71+
echo "Module file not found: $module_path/.module.toml"
72+
exit 1
73+
fi
74+
75+
module_name="$(yq .module.name $module_path/.module.toml)"
76+
module_version="$(yq .module.version $module_path/.module.toml)"
77+
module_type="$(yq .module.type $module_path/.module.toml)"
78+
79+
if ! echo "$module_version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
80+
echo "Invalid version format: $module_version (expected: x.y.z)"
81+
exit 1
82+
fi
83+
84+
if [[ "$module_type" != "terraform" ]]; then
85+
echo "Invalid module type: $module_type (expected: terraform)"
86+
exit 1
87+
fi
88+
89+
echo "Packaging $module_name-$module_version"
90+
package_file="$temp_dir/terraform-${module_name}-${module_version}.tar.gz"
91+
92+
tar \
93+
--exclude='.module.toml' \
94+
--exclude='.terraform' \
95+
--exclude='*.tfstate*' \
96+
--exclude='*_override.tf*' \
97+
-C $module_path \
98+
-czvf "$package_file" .
99+
100+
echo -e "\nPackage created: $package_file"
101+
102+
if [[ "$module_publish" == "yes" ]]; then
103+
echo -e "\nPublishing $module_name-$module_version"
104+
cloudsmith push terraform \
105+
--republish \
106+
elastio/public \
107+
"$package_file"
108+
else
109+
echo -e "\nSkipping publish"
110+
fi
111+
112+
if [[ "$tag_push" == "yes" ]]; then
113+
echo -e "\nTagging $module_name-$module_version"
114+
git tag -a "$module_name-$module_version" -m "Release $module_name $module_version"
115+
git push origin "$module_name-$module_version"
116+
else
117+
echo -e "\nSkipping tag push"
118+
fi
119+
120+
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
121+
{
122+
echo "### Module: $module_name"
123+
echo "- Version: $module_version"
124+
[[ "$module_publish" == "yes" ]] && echo "- Status: Published ✅"
125+
[[ "$tag_push" == "yes" ]] && echo "- Tag: $module_name-$module_version"
126+
} >> "$GITHUB_STEP_SUMMARY"
127+
fi

.github/workflows/release.yml

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ jobs:
1919
release-module:
2020
runs-on: ubuntu-latest
2121
needs: ["collect-modules"]
22+
permissions:
23+
contents: write
24+
actions: write
2225
strategy:
2326
matrix:
2427
module: ${{fromJson(needs.collect-modules.outputs.tf-modules)}}
2528
fail-fast: false
2629

2730
steps:
31+
- uses: actions/checkout@v4
32+
2833
- uses: cloudsmith-io/cloudsmith-cli-action@v1.0.3
2934
with:
3035
api-key: ${{ secrets.CLOUDSMITH_API_TOKEN }}
3136

32-
- uses: actions/checkout@v4
33-
3437
- name: Fetch tags
3538
run: git fetch --prune --tags
3639

@@ -47,42 +50,10 @@ jobs:
4750
echo "module_version=$module_version" >> $GITHUB_OUTPUT
4851
echo "tag_exists=$tag_exists" >> $GITHUB_OUTPUT
4952
50-
- name: publish module
53+
- name: release module
5154
if: steps.module-info.outputs.tag_exists == 'false'
52-
run: |
53-
module_path="${{ matrix.module }}"
54-
module_name=$(yq .module.name $module_path/.releaserc.yaml)
55-
module_version=$(yq .module.version $module_path/.releaserc.yaml)
56-
57-
echo "Packaging $module_name-$module_version"
58-
59-
tar \
60-
--exclude='.releaserc.yaml' \
61-
--exclude='.terraform' \
62-
--exclude='*.tfstate*' \
63-
--exclude='*_override.tf*' \
64-
-C $module_path \
65-
-czvf terraform-${module_name}-${module_version}.tar.gz .
66-
67-
echo "Publishing $module_name-$module_version"
68-
69-
cloudsmith push terraform \
70-
elastio/public \
71-
--republish \
72-
terraform-${module_name}-${module_version}.tar.gz
73-
74-
- name: push tag
75-
if: steps.module-info.outputs.tag_exists == 'false'
76-
run: |
77-
module_name=${{ steps.module-info.outputs.module_name }}
78-
module_version=${{ steps.module-info.outputs.module_version }}
79-
80-
git tag $module_name-$module_version
81-
git push origin $module_name-$module_version
82-
83-
- name: Create release summary
84-
if: steps.module-info.outputs.tag_exists == 'false'
85-
run: |
86-
echo "### Module: ${{ steps.module-info.outputs.module_name }}" >> $GITHUB_STEP_SUMMARY
87-
echo "- Version: ${{ steps.module-info.outputs.module_version }}" >> $GITHUB_STEP_SUMMARY
88-
echo "- Status: Published ✅" >> $GITHUB_STEP_SUMMARY
55+
run: >
56+
.github/scripts/release-tf-module.sh
57+
--module-path ${{ matrix.module }}
58+
--publish
59+
--tag-push

asset-account/terraform/stack-set/.releaserc.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)