Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/access-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Access Report

on:
workflow_dispatch:
inputs:
organization:
description: Organization config to report on
required: true

defaults:
run:
shell: bash

jobs:
report:
permissions:
contents: read
name: Access report
runs-on: ubuntu-latest
environment: read
env:
TF_IN_AUTOMATION: 1
TF_INPUT: 0
TF_WORKSPACE: ${{ inputs.organization }}
AWS_ACCESS_KEY_ID: ${{ secrets.RO_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.RO_AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup terraform
uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v4.0.0
with:
terraform_version: 1.12.0
terraform_wrapper: false
- name: Initialize terraform
run: terraform init
working-directory: terraform
- name: Install pnpm
uses: pnpm/action-setup@91ab88e2619ed1f46221f0ba42d1492c02baf788 # v6.0.6
with:
version: 10
- name: Use Node.js lts/*
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: lts/*
cache: ''
- name: Initialize scripts
run: pnpm install --frozen-lockfile && pnpm run build
working-directory: scripts
- name: Generate access report
run: node --input-type=module --eval "import {runDescribeAccessChanges} from './lib/actions/shared/describe-access-changes.js'; await runDescribeAccessChanges();"
working-directory: scripts
env:
ACCESS_REPORT_PATH: ../ACCESS_REPORT.md
- name: Publish access report summary
run: cat ACCESS_REPORT.md >> "$GITHUB_STEP_SUMMARY"
- name: Upload access report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: access-report-${{ env.TF_WORKSPACE }}
path: ACCESS_REPORT.md
if-no-files-found: error
retention-days: 14
124 changes: 117 additions & 7 deletions .github/workflows/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,65 @@ jobs:
GITHUB_APP_PEM_FILE: ${{ secrets.RO_GITHUB_APP_PEM_FILE }}
run: node lib/actions/find-sha-for-plan.js
working-directory: scripts
apply:
classify:
needs: [prepare]
if: needs.prepare.outputs.sha != '' && needs.prepare.outputs.workspaces != ''
permissions:
contents: read
name: Classify
runs-on: ubuntu-latest
environment: read
outputs:
matrix: ${{ steps.classify.outputs.matrix }}
env:
TF_IN_AUTOMATION: 1
TF_INPUT: 0
AWS_ACCESS_KEY_ID: ${{ secrets.RO_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.RO_AWS_SECRET_ACCESS_KEY }}
WORKSPACES: ${{ needs.prepare.outputs.workspaces }}
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup terraform
uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v4.0.0
with:
terraform_version: 1.12.0
terraform_wrapper: false
- name: Initialize terraform
run: terraform init
working-directory: terraform
- name: Install pnpm
uses: pnpm/action-setup@91ab88e2619ed1f46221f0ba42d1492c02baf788 # v6.0.6
with:
version: 10
- name: Use Node.js lts/*
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: lts/*
cache: ''
- run: pnpm install --frozen-lockfile && pnpm run build
working-directory: scripts
- name: Classify workspaces
id: classify
env:
MODE: write
run: node lib/actions/classify-allow-destroy.js
working-directory: scripts
apply:
needs: [prepare, classify]
if: needs.prepare.outputs.sha != '' && needs.prepare.outputs.workspaces != ''
permissions:
actions: read
contents: read
strategy:
fail-fast: false
matrix:
workspace: ${{ fromJson(needs.prepare.outputs.workspaces) }}
matrix: ${{ fromJson(needs.classify.outputs.matrix) }}
name: Apply
runs-on: ubuntu-latest
environment: write
environment: ${{ matrix.environment }}
env:
TF_IN_AUTOMATION: 1
TF_INPUT: 0
Expand All @@ -84,19 +130,83 @@ jobs:
terraform_wrapper: false
- name: Initialize terraform
run: terraform init
- name: Allow destroy in guarded environment
if: matrix.environment == 'write-allow-destroy'
env:
ALLOW_DESTROY: ${{ vars.ALLOW_DESTROY }}
run: |
if [[ "${ALLOW_DESTROY}" != "true" ]]; then
echo "The write-allow-destroy environment must define ALLOW_DESTROY=true."
exit 1
fi
cp allow_destroy_override.tf.disabled allow_destroy_override.tf
- name: Summarize apply target
env:
REVIEWED_SHA: ${{ needs.prepare.outputs.sha }}
ENVIRONMENT_REASONS: ${{ toJson(matrix.environmentReasons) }}
run: |
{
echo '## Apply target'
echo ''
echo "- Reviewed SHA: \`${REVIEWED_SHA}\`"
echo "- Workspace: \`${TF_WORKSPACE}\`"
echo "- Environment: \`${{ matrix.environment }}\`"
if [[ "$(jq 'length' <<< "${ENVIRONMENT_REASONS}")" == '0' ]]; then
echo "- Environment reason: no allow-destroy changes detected"
else
echo "- Environment reason:"
jq -r '.[] | " - " + .' <<< "${ENVIRONMENT_REASONS}"
fi
echo "- Reviewed plan artifact: \`${TF_WORKSPACE}_${REVIEWED_SHA}.tfplan\`"
} >> "$GITHUB_STEP_SUMMARY"
- name: Download reviewed terraform plan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ needs.prepare.outputs.sha }}
run: gh run download -n "${TF_WORKSPACE}_${SHA}.tfplan" --repo "${GITHUB_REPOSITORY}"
- name: Show reviewed terraform plan
run: |
terraform show -no-color "${TF_WORKSPACE}.tfplan" > "${TF_WORKSPACE}.reviewed.txt"
{
echo '## Reviewed Terraform plan'
echo ''
echo "<details><summary>${TF_WORKSPACE}.tfplan</summary>"
echo ''
echo '~~~~terraform'
sed 's/^~~~~/~~~~ /' "${TF_WORKSPACE}.reviewed.txt"
echo '~~~~'
echo ''
echo '</details>'
} >> "$GITHUB_STEP_SUMMARY"
- name: Replan merged commit
run: |
terraform show -json > $TF_WORKSPACE.tfstate.json
terraform show -json > "$TF_WORKSPACE.tfstate.json"
terraform plan -refresh=false -lock=false -out="${TF_WORKSPACE}.merged.tfplan" -no-color
- name: Compare reviewed and merged plans
- name: Show merged terraform plan
run: |
terraform show -no-color "${TF_WORKSPACE}.tfplan" > "${TF_WORKSPACE}.reviewed.txt"
terraform show -no-color "${TF_WORKSPACE}.merged.tfplan" > "${TF_WORKSPACE}.merged.txt"
{
echo '## Merged Terraform plan'
echo ''
echo "<details><summary>${TF_WORKSPACE}.merged.tfplan</summary>"
echo ''
echo '~~~~terraform'
sed 's/^~~~~/~~~~ /' "${TF_WORKSPACE}.merged.txt"
echo '~~~~'
echo ''
echo '</details>'
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload apply plan summaries
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: apply-plans-${{ env.TF_WORKSPACE }}-${{ needs.prepare.outputs.sha }}
path: |
terraform/${{ env.TF_WORKSPACE }}.reviewed.txt
terraform/${{ env.TF_WORKSPACE }}.merged.txt
if-no-files-found: error
retention-days: 14
- name: Compare reviewed and merged plans
run: |
diff -u "${TF_WORKSPACE}.reviewed.txt" "${TF_WORKSPACE}.merged.txt"
- name: Terraform Apply
run: |
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/convert-member-to-outside-collaborator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Convert Member to Outside Collaborator (temporary)

# Remove after adopting provider PR #3608 and migrating membership destroy settings.
on:
workflow_dispatch:
inputs:
organization:
description: Organization containing the members
required: true
type: string
usernames:
description: Comma- or whitespace-separated members to convert, preserving repository access
required: true
type: string

jobs:
convert:
runs-on: ubuntu-latest
environment: write-allow-destroy
permissions: {}
env:
ORGANIZATION: ${{ inputs.organization }}
USERNAMES: ${{ inputs.usernames }}
defaults:
run:
shell: bash
steps:
- name: Validate conversion request
id: validate
env:
ALLOW_DESTROY: ${{ vars.ALLOW_DESTROY }}
run: |
if [[ "${ALLOW_DESTROY}" != 'true' ]]; then
echo 'The write-allow-destroy environment must define ALLOW_DESTROY=true.'
exit 1
fi
if [[ ! "${ORGANIZATION}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then
echo 'Specify one organization using its GitHub login name.'
exit 1
fi
usernames=()
while IFS= read -r username; do
[[ -z "${username}" ]] && continue
if [[ ! "${username}" =~ ^[A-Za-z0-9][A-Za-z0-9-]*$ ]]; then
echo "Invalid GitHub username: ${username}"
exit 1
fi
usernames+=("${username}")
done < <(printf '%s' "${USERNAMES}" | tr ',[:space:]' '\n' | tr '[:upper:]' '[:lower:]' | sort -u)
if [[ ${#usernames[@]} -eq 0 ]]; then
echo 'Specify at least one GitHub username.'
exit 1
fi
printf 'usernames=%s\n' "${usernames[*]}" >> "$GITHUB_OUTPUT"
- name: Generate organization app token
id: token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
with:
app-id: ${{ secrets.RW_GITHUB_APP_ID }}
private-key: ${{ secrets.RW_GITHUB_APP_PEM_FILE }}
owner: ${{ inputs.organization }}
permission-members: write
- name: Convert members
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
USERNAMES: ${{ steps.validate.outputs.usernames }}
run: |
read -r -a usernames <<< "${USERNAMES}"
for username in "${usernames[@]}"; do
membership_state="$(gh api "orgs/${ORGANIZATION}/memberships/${username}" --jq '.state')"
if [[ "${membership_state}" != 'active' ]]; then
echo "${username} is not an active member. Pending invitations must be accepted first. No members were converted."
exit 1
fi
done
{
echo '## Outside collaborator conversions'
echo "Organization: ${ORGANIZATION}. Existing repository access is retained where GitHub permits; team membership is removed."
echo
echo "Next: run Sync with workspaces=${ORGANIZATION}. This workflow does not update Terraform state or YAML."
echo 'Save any merged but unapplied PR diffs first: Sync rewrites YAML from live GitHub and can lose intended changes that have not been applied.'
echo 'Then update/rebase the original PR (or open a follow-up PR if already merged), restore intended access removals, and review a fresh Plan before merging.'
echo
echo 'Temporary workaround until provider PR https://github.com/integrations/terraform-provider-github/pull/3608 is released, adopted, and membership state is migrated.'
echo
} >> "$GITHUB_STEP_SUMMARY"
for username in "${usernames[@]}"; do
if ! gh api --method PUT "orgs/${ORGANIZATION}/outside_collaborators/${username}" -F async=false; then
echo "- Failed: ${username}. Stopped; later users were not attempted. Check live membership before retrying; omit users already converted and run Sync for successful conversions." >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
echo "- Converted: ${username}" >> "$GITHUB_STEP_SUMMARY"
done
21 changes: 17 additions & 4 deletions .github/workflows/fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,23 @@ jobs:
id: fix
run: node lib/actions/fix-yaml-config.js
working-directory: scripts
env:
ACCESS_REPORT_PATH: ../ACCESS_REPORT.md
- name: Publish access report summary
if: always() && hashFiles('ACCESS_REPORT.md') != ''
run: cat ACCESS_REPORT.md >> "$GITHUB_STEP_SUMMARY"
- name: Upload access report
if: always() && hashFiles('ACCESS_REPORT.md') != ''
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: access-report-${{ env.TF_WORKSPACE }}
path: ACCESS_REPORT.md
if-no-files-found: error
retention-days: 14
- name: Upload YAML config
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ env.TF_WORKSPACE }}.yml
name: fixed-config-${{ env.TF_WORKSPACE }}
path: github/${{ env.TF_WORKSPACE }}.yml
if-no-files-found: error
retention-days: 1
Expand Down Expand Up @@ -164,10 +177,10 @@ jobs:
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: artifacts
pattern: fixed-config-*
merge-multiple: true
- name: Copy YAML configs
run: |
shopt -s globstar
cp artifacts/**/*.yml head/github
run: cp artifacts/*.yml head/github
- name: Check if github was modified
id: github-modified
run: |
Expand Down
Loading