Skip to content

Commit 297a201

Browse files
feat: refactor workflows to use Github App instead of PAT (#34)
This PR refactors the GitHub workflow configurations to use GitHub App authentication instead of a PAT and updates documentation in the README accordingly. Key changes include the replacement of legacy workflows (terraform-vcs.yml and terraform-workspace.yml) with new workflows (terraform-stack.yml, terraform-module-test.yml, and terraform-module-release.yml) and adjustments to the codeowners file.
1 parent fed6539 commit 297a201

9 files changed

Lines changed: 1016 additions & 1393 deletions

.github/CODEOWNERS

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,4 @@
44
# More details are here: https://help.github.com/articles/about-codeowners/
55

66
# The '*' pattern is global owners.
7-
8-
# Order is important. The last matching pattern has the most precedence.
9-
# The folders are ordered as follows:
10-
11-
# In each subsection folders are ordered first by depth, then alphabetically.
12-
# This should make it easy to add new rules without breaking existing ones.
13-
14-
# Workflows
15-
/.github/* @stefano-franco @nuvibit-team
16-
/.github/workflows/* @stefano-franco @nuvibit-team
7+
# There are currently no codeowners defined.

.github/workflows/terraform-module-release.yml

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ on:
88
default: 'ubuntu-latest'
99
required: false
1010
type: string
11-
toggle_branch_protection:
12-
description: 'Temporary disable branch protection to allow release action to push updates to changelog'
13-
default: true
14-
required: false
15-
type: boolean
1611
semantic_version:
1712
description: 'Specify specifying version range for semantic-release'
1813
default: '18.0.0'
@@ -34,7 +29,11 @@ on:
3429
required: false
3530
type: string
3631
secrets:
37-
GHE_API_TOKEN:
32+
# GitHub App credentials to use instead of default GITHUB_TOKEN to avoid not triggering workflow runs on commit
33+
# make sure the Github App has the necessary permissions to push to the repository (bypassing branch protection rules)
34+
GH_APP_ID:
35+
required: true
36+
GH_APP_PRIVATE_KEY:
3837
required: true
3938

4039
# Ensures that only one workflow runs at a time
@@ -45,39 +44,22 @@ jobs:
4544
runs-on: ${{ inputs.github_runner }}
4645

4746
steps:
47+
- name: Get Github Access Token
48+
id: github_app_token
49+
uses: actions/create-github-app-token@v2
50+
with:
51+
app-id: ${{ secrets.GH_APP_ID }}
52+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
53+
# if owner and repositories are empty, access will be scoped to only the current repository
54+
# owner: ''
55+
# repositories: ''
56+
4857
- name: Checkout
4958
uses: actions/checkout@v4
5059
with:
5160
persist-credentials: false
5261
fetch-depth: 0
5362

54-
- name: Check Branch Protection
55-
if: ${{ inputs.toggle_branch_protection }}
56-
uses: octokit/request-action@v2.x
57-
id: get_branch_protection
58-
continue-on-error: true
59-
with:
60-
route: GET /repos/${{ github.repository }}/branches/${{ inputs.release_branch }}/protection
61-
env:
62-
GITHUB_TOKEN: ${{ secrets.GHE_API_TOKEN }}
63-
64-
- name: Temporarily Disable Branch Protection
65-
if: ${{ inputs.toggle_branch_protection && steps.get_branch_protection.outputs.status == '200' }}
66-
uses: octokit/request-action@v2.x
67-
id: disable_branch_protection
68-
with:
69-
route: PUT /repos/${{ github.repository }}/branches/${{ inputs.release_branch }}/protection
70-
required_status_checks: |
71-
null
72-
enforce_admins: |
73-
false
74-
required_pull_request_reviews: |
75-
null
76-
restrictions: |
77-
null
78-
env:
79-
GITHUB_TOKEN: ${{ secrets.GHE_API_TOKEN }}
80-
8163
- name: Release Terraform Module
8264
uses: cycjimmy/semantic-release-action@v4
8365
id: semantic
@@ -87,43 +69,12 @@ jobs:
8769
extends: |
8870
${{ inputs.semantic_release_config }}
8971
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91-
92-
- name: Enable Branch Protection
93-
if: ${{ always() && inputs.toggle_branch_protection && steps.get_branch_protection.outputs.status == '200' }}
94-
uses: octokit/request-action@v2.x
95-
id: enable_branch_protection
96-
with:
97-
route: PUT /repos/${{ github.repository }}/branches/${{ inputs.release_branch }}/protection
98-
required_status_checks: |
99-
{
100-
"strict": ${{ toJson(fromJson(steps.get_branch_protection.outputs.data).required_status_checks.strict) || null }},
101-
"checks": ${{ toJson(fromJson(steps.get_branch_protection.outputs.data).required_status_checks.checks) || null }}
102-
}
103-
enforce_admins: |
104-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).enforce_admins.enabled) || null }}
105-
required_pull_request_reviews: |
106-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).required_pull_request_reviews) || null }}
107-
restrictions: |
108-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).restrictions) || null }}
109-
required_linear_history: |
110-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).required_linear_history.enabled) || null }}
111-
allow_force_pushes: |
112-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).allow_force_pushes.enabled) || null }}
113-
allow_deletions: |
114-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).allow_deletions.enabled) || null }}
115-
block_creations: |
116-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).block_creations.enabled) || null }}
117-
required_conversation_resolution: |
118-
${{ toJson(fromJson(steps.get_branch_protection.outputs.data).required_conversation_resolution.enabled) || null }}
119-
env:
120-
GITHUB_TOKEN: ${{ secrets.GHE_API_TOKEN }}
72+
GITHUB_TOKEN: ${{ steps.github_app_token.outputs.token }}
12173

12274
- name: Workflow Summary
12375
if: ${{ always() }}
12476
env:
125-
TOGGLE_BRANCH_PROTECTION: ${{ fromJSON('[":white_check_mark:", ":x:"]')[inputs.toggle_branch_protection && steps.get_branch_protection.outputs.status == '200'] }}
126-
NEW_RELEASE_PUBLISHED: ${{ fromJSON('[":white_check_mark:", ":x:"]')[steps.semantic.outputs.new_release_published != 'true'] }}
77+
NEW_RELEASE_PUBLISHED: ${{ fromJSON('[":white_check_mark:", ":heavy_minus_sign:"]')[steps.semantic.outputs.new_release_published != 'true'] }}
12778
LAST_RELEASE_VERSION: ${{ steps.semantic.outputs.last_release_version }}
12879
NEW_RELEASE_VERSION: ${{ steps.semantic.outputs.new_release_version }}
12980
run: |

0 commit comments

Comments
 (0)