Added condition to release job. #19
Workflow file for this run
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
name: Release Branch Test | |
on: | |
push: | |
branches: | |
- module-release | |
jobs: | |
find-modules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Find all terraform modules | |
id: find | |
uses: bendrucker/find-terraform-modules@v1 | |
- name: Show all matching modules | |
shell: bash | |
run: | | |
mods=(${{ join(fromJSON(steps.find.outputs.modules), ' ') }}) | |
printf "%s\n" "${mods[@]}" | |
- name: Find all changed files | |
id: diff | |
uses: technote-space/get-diff-action@v6 | |
with: | |
FORMAT: json | |
- name: Show changed files | |
run: | | |
echo "${{ steps.diff.outputs.diff }}" | |
- name: Get the modified modules | |
id: modified | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const modules = ${{ steps.find.outputs.modules }} | |
const diff = ${{ steps.diff.outputs.diff }} | |
const modifiedModules = modules.filter( | |
(module) => { | |
return !!diff.find(file => new RegExp(`^${module}/.+`).test(file)) | |
} | |
) | |
core.setOutput('modules', modifiedModules) | |
- name: Show modified modules | |
run: | | |
echo "${{ steps.modified.outputs.modules }}" | |
outputs: | |
modules: ${{ steps.modified.outputs.modules }} | |
release: | |
name: Release updated modules | |
runs-on: ubuntu-latest | |
needs: find-modules | |
if: ${{ needs.find-modules.outputs.modules != '' && toJson(fromJson(needs.find-modules.outputs.modules)) != '[]' }} | |
strategy: | |
matrix: | |
module: ${{fromJson(needs.find-modules.outputs.modules)}} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- run: cp ${{ matrix.module }}/.cz.yaml .cz.yaml | |
- name: Bump version and create changelog | |
id: bump | |
uses: commitizen-tools/commitizen-action@master | |
with: | |
push: true | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
changelog_increment_filename: release.md | |
- name: Get the module name | |
id: module_name | |
run: | | |
MODULE_PATH="${{ matrix.module }}" | |
MODULE_NAME="${MODULE_PATH//\//_}" | |
echo "name=${MODULE_NAME}" >> $GITHUB_OUTPUT | |
- run: echo '${{ steps.module_name.outputs.name }}' | |
- name: Bundle the module | |
run: tar czf "${{ steps.module_name.outputs.name }}-${{ steps.bump.outputs.version }}.tar.gz" ${{ matrix.module }} | |
- name: Create release | |
uses: softprops/action-gh-release@v2 | |
with: | |
body_path: release.md | |
tag_name: ${{ steps.module_name.outputs.name }}-${{ steps.bump.outputs.version }} | |
files: | | |
release.md | |
${{ steps.module_name.outputs.name }}-${{ steps.bump.outputs.version }}.tar.gz |