release workflow, fixes for module pr (#2) #2
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
on: | |
push: | |
branches: | |
- main | |
paths: | |
- modules/** | |
permissions: | |
contents: write | |
pull-requests: write | |
packages: write | |
name: release-please-module | |
jobs: | |
find-release-changes: | |
name: Change finder for modules folders | |
runs-on: ubuntu-latest | |
outputs: | |
module-paths: ${{ steps.set-output.outputs.module-paths }} | |
steps: | |
- uses: actions/checkout@v4 | |
- run: npm install @octokit/action | |
name: Install Octokit | |
- id: change-finder | |
uses: actions/github-script@v6.4.1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const octokit = new Octokit() | |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); | |
const latestRelease = await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { | |
owner: owner, | |
repo: repo, | |
headers: { | |
'X-GitHub-Api-Version': '2022-11-28' | |
} | |
}) | |
console.log(`latest release: ${JSON.stringify(latestRelease.data)}`); | |
execSync('git pull --tags'); | |
const status = execSync(`git diff --name-only ${latestRelease.data.tag_name} origin/master`, { encoding: 'utf-8'}); | |
console.log(status); | |
const changes = status.split('\n'); | |
let modules_paths = new Set(); | |
for (const change of changes) { | |
if (change.startsWith('modules/')) { | |
const library = change.split('/')[1]; | |
modules_paths.add(library); | |
}; | |
} | |
modules_paths = Array.from(modules_paths); | |
return JSON.stringify(modules_paths); | |
- name: Set output | |
id: set-output | |
run: echo "{module-paths}=${{ steps.change-finder.outputs.result }}" >> $GITHUB_OUTPUT | |
release-pr: | |
runs-on: ubuntu-latest | |
needs: find-release-changes | |
strategy: | |
fail-fast: false | |
matrix: | |
module: ${{fromJson(needs.find-release-changes.outputs.module-paths)}} | |
steps: | |
- uses: google-github-actions/release-please-action@v3 | |
id: release-please | |
with: | |
path: modules/${{ matrix.module }} | |
changelog-path: CHANGELOG.md | |
token: ${{ secrets.GITHUB_TOKEN }} | |
release-type: terraform-module | |
package-name: ${{ matrix.module }} | |
monorepo-tags: true | |
command: release-pr | |
release-please-release: | |
runs-on: ubuntu-latest | |
needs: find-release-changes | |
strategy: | |
fail-fast: false | |
matrix: | |
module: ${{fromJson(needs.find-release-changes.outputs.module-paths)}} | |
steps: | |
- uses: google-github-actions/release-please-action@v3 | |
id: tag-release | |
with: | |
path: modules/${{ matrix.module }} | |
changelog-path: CHANGELOG.md | |
token: ${{ secrets.GITHUB_TOKEN }} | |
release-type: terraform-module | |
monorepo-tags: true | |
package-name: ${{ matrix.module }} | |
command: github-release |