Skip to content

Commit

Permalink
Merge branch 'main' into opentofu
Browse files Browse the repository at this point in the history
  • Loading branch information
goruha authored Jun 4, 2024
2 parents 551001c + f350756 commit 6eb7f84
Show file tree
Hide file tree
Showing 27 changed files with 635 additions and 5 deletions.
164 changes: 163 additions & 1 deletion .github/workflows/shared-release-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ on:
required: false
default: '["ubuntu-latest"]'

permissions: {}
permissions:
id-token: write
contents: write
pull-requests: write

jobs:
major-release-tagger:
Expand Down Expand Up @@ -39,3 +42,162 @@ jobs:
- uses: cloudposse/github-action-release-branch-manager@v2
with:
token: ${{ steps.github-app.outputs.token }}

release-commenter:
runs-on: ${{ fromJSON(inputs.runs-on) }}
steps:
- uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
script: |
// Function to check if a value is unique in an array
function onlyUnique(value, index, array) {
return array.indexOf(value) === index;
}
// Function to create or update a comment for a pull request (PR) associated with a release
async function createOrUpdateCommentForPR(pr_id, release) {
// Parameters for fetching comments related to the PR
const parameters = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_id,
per_page: 100,
}
// Initialize existingComment variable
let existingComment = null;
// Constructing the message to be posted or updated as a comment
const messageId = `<!-- release-pr-comment:${release.id} -->`;
const message = `
${messageId}
These changes were released in [${release.name}](${release.html_url}).
`;
// Iterating through all comments related to the PR
const allComments = github.paginate.iterator(github.rest.issues.listComments, parameters);
for await (comments of allComments) {
// Check if the message id is present in any of the comments
found = comments.data.find(({ body }) => {
return (body?.search(messageId) != -1) > -1;
});
if (found) {
break; // Exit the loop if the comment is found
}
}
// If the comment is found, update it; otherwise, create a new comment
if (found) {
console.log(`Comment found`);
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: found.id,
body: message
});
} else {
console.log(`Comment not found`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_id,
body: message
});
}
}
// Retrieving the ID of the current release
release_id = context.payload.release.id;
// Fetching details of the current release
currentReleaseResponse = await github.rest.repos.getRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id,
});
currentRelease = currentReleaseResponse.data;
// Extracting tag name and target branch from the current release
currentTag = currentRelease.tag_name;
currentBranch = currentRelease.target_commitish;
// Listing all releases of the repository
releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
// Initializing variables for storing information about the previous release
previousRelease = null;
currentReleaseFound = false;
// Iterating through releases to find the previous release relative to the current one
for (release of releases.data) {
if (currentReleaseFound) {
previousRelease = release;
break;
} else if (release.tag_name == currentTag) {
currentReleaseFound = true;
}
}
// If no previous release is found, log a message and return
if (previousRelease == null) {
console.log(`No previous release found for ${currentTag}`);
return;
}
// Comparing commits between the current and previous releases
commitsResponse = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: previousRelease.tag_name,
head: currentRelease.tag_name,
});
commits = commitsResponse.data;
// Initializing an array to store pull request numbers associated with the commits
pull_requests = [];
// Iterating through commits to find associated pull requests and extracting their numbers
for (commit of commits.commits) {
responseCommit = await github.rest.git.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: commit.sha,
});
// GraphQL query to fetch details about the commit, including associated pull requests
const query = `
{
resource(url: "${context.payload.repository.html_url}/commit/${commit.sha}") {
... on Commit {
messageHeadlineHTML
messageBodyHTML
associatedPullRequests(first: 10) {
pageInfo { hasNextPage }
edges { node { number } }
}
}
}
}
`;
response = await github.graphql(query);
// Extracting pull request numbers from the GraphQL response
for (edge of response.resource.associatedPullRequests.edges) {
pull_requests.push(edge.node.number);
}
}
// Iterating through unique pull request numbers and creating or updating comments for them
for (id of pull_requests.filter(onlyUnique)) {
await createOrUpdateCommentForPR(id, currentRelease);
}
6 changes: 3 additions & 3 deletions .github/workflows/shared-terraform-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:

jobs:
ci-terraform:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-terraform.yml@shared-workflows
uses: cloudposse/github-actions-workflows/.github/workflows/ci-terraform.yml@main
name: "CI"
with:
# Workaround for https://github.com/community/community/discussions/9099
Expand All @@ -28,15 +28,15 @@ jobs:
runs-on: ${{ inputs.runs-on }}

ci-readme:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-readme.yml@shared-workflows
uses: cloudposse/github-actions-workflows/.github/workflows/ci-readme.yml@main
name: "Readme"
if: ${{ github.event_name == 'push' }}
with:
runs-on: ${{ inputs.runs-on }}
secrets: inherit

ci-codeowners:
uses: cloudposse/github-actions-workflows/.github/workflows/ci-codeowners.yml@shared-workflows
uses: cloudposse/github-actions-workflows/.github/workflows/ci-codeowners.yml@main
name: "CI"
with:
is_fork: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}
Expand Down
5 changes: 5 additions & 0 deletions migrate/migrations/20240529/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## what
- Update workflow (`.github/workflows/release.yaml`) to have permission to comment on PR

## why
- Add comment to PR when it is released
14 changes: 14 additions & 0 deletions migrate/migrations/20240529/repos-00
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cloudposse/github-action-test-action
cloudposse/github-action-atmos-get-setting
cloudposse/github-action-pre-commit
cloudposse/github-action-config-levels
cloudposse/github-action-atmos-terraform-drift-detection
cloudposse/github-action-matrix-outputs-write
cloudposse/github-action-setup-atmos
cloudposse/github-action-docker-build-push
cloudposse/github-action-docker-image-exists
cloudposse/github-action-docker-promote
cloudposse/github-action-deploy-argocd
cloudposse/github-action-deploy-helmfile
cloudposse/github-action-auto-release
cloudposse/github-action-preview-environment-controller
15 changes: 15 additions & 0 deletions migrate/migrations/20240529/repos-01
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cloudposse/github-action-kubernetes-environment
cloudposse/github-action-yaml-config-query
cloudposse/github-action-run-ecspresso
cloudposse/github-action-jq
cloudposse/github-action-auto-format
cloudposse/github-action-sync-docker-repos
cloudposse/github-action-matrix-extended
cloudposse/github-action-atmos-terraform-select-components
cloudposse/github-action-atmos-terraform-apply
cloudposse/github-action-atmos-affected-trigger-spacelift
cloudposse/github-action-matrix-outputs-read
cloudposse/github-action-release-label-validator
cloudposse/github-action-atmos-terraform-plan
cloudposse/github-action-atmos-affected-stacks
cloudposse/github-action-atmos-terraform-drift-remediation
16 changes: 16 additions & 0 deletions migrate/migrations/20240529/repos-02
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cloudposse/github-action-release-branch-manager
cloudposse/github-action-major-release-tagger
cloudposse/github-action-validate-codeowners
cloudposse/github-action-terraform-auto-context
cloudposse/github-action-atmos-component-updater
cloudposse/github-action-deploy-ecspresso
cloudposse/github-action-wait-commit-status
cloudposse/github-action-secret-outputs
cloudposse/github-action-interface-environment
cloudposse/github-action-terratest
cloudposse/github-action-spacelift-stack-deploy
cloudposse/github-action-aws-region-reduction-map
cloudposse/github-action-docker-compose-test-run
cloudposse/github-action-seek-deployment
cloudposse/github-action-preview-labels-cleanup
cloudposse/github-action-monorepo-random-controller
5 changes: 5 additions & 0 deletions migrate/migrations/20240529/repos-03
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cloudposse/github-action-deploy-spacelift
cloudposse/github-action-telemetry
cloudposse/github-action-mega-linter
cloudposse/github-action-datadog-notify
cloudposse/github-action-pull-request-labeling
5 changes: 5 additions & 0 deletions migrate/migrations/20240529/repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
gh repo list cloudposse --limit 500 --json name,owner \
--jq '.[] | select(.name | test("^github-action-")) | .owner.login + "/" + .name' > repos.txt

split -d -l 16 repos.txt repos-
51 changes: 51 additions & 0 deletions migrate/migrations/20240529/repos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cloudposse/github-action-test-action
cloudposse/github-action-atmos-get-setting
cloudposse/github-action-pre-commit
cloudposse/github-action-config-levels
cloudposse/github-action-atmos-terraform-drift-detection
cloudposse/github-action-matrix-outputs-write
cloudposse/github-action-setup-atmos
cloudposse/github-action-docker-build-push
cloudposse/github-action-docker-image-exists
cloudposse/github-action-docker-promote
cloudposse/github-action-deploy-argocd
cloudposse/github-action-deploy-helmfile
cloudposse/github-action-auto-release
cloudposse/github-action-preview-environment-controller
cloudposse/github-action-kubernetes-environment
cloudposse/github-action-yaml-config-query
cloudposse/github-action-run-ecspresso
cloudposse/github-action-terraform-plan-storage
cloudposse/github-action-jq
cloudposse/github-action-auto-format
cloudposse/github-action-sync-docker-repos
cloudposse/github-action-matrix-extended
cloudposse/github-action-atmos-terraform-select-components
cloudposse/github-action-atmos-terraform-apply
cloudposse/github-action-atmos-affected-trigger-spacelift
cloudposse/github-action-matrix-outputs-read
cloudposse/github-action-release-label-validator
cloudposse/github-action-atmos-terraform-plan
cloudposse/github-action-atmos-affected-stacks
cloudposse/github-action-atmos-terraform-drift-remediation
cloudposse/github-action-release-branch-manager
cloudposse/github-action-major-release-tagger
cloudposse/github-action-validate-codeowners
cloudposse/github-action-terraform-auto-context
cloudposse/github-action-atmos-component-updater
cloudposse/github-action-deploy-ecspresso
cloudposse/github-action-wait-commit-status
cloudposse/github-action-secret-outputs
cloudposse/github-action-interface-environment
cloudposse/github-action-terratest
cloudposse/github-action-spacelift-stack-deploy
cloudposse/github-action-aws-region-reduction-map
cloudposse/github-action-docker-compose-test-run
cloudposse/github-action-seek-deployment
cloudposse/github-action-preview-labels-cleanup
cloudposse/github-action-monorepo-random-controller
cloudposse/github-action-deploy-spacelift
cloudposse/github-action-telemetry
cloudposse/github-action-mega-linter
cloudposse/github-action-datadog-notify
cloudposse/github-action-pull-request-labeling
6 changes: 6 additions & 0 deletions migrate/migrations/20240529/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title "Update release workflow to allow pull-requests: write"

install .github/workflows/release.yml

# Merge the PR
auto_merge
5 changes: 5 additions & 0 deletions migrate/migrations/20240530/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## what
- Update workflow (`.github/workflows/release.yaml`) to have permission to comment on PR

## why
- So we can support commenting on PRs with a link to the release
16 changes: 16 additions & 0 deletions migrate/migrations/20240530/repos-00
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cloudposse/terraform-aws-rds
cloudposse/terraform-aws-ec2-autoscale-group
cloudposse/terraform-aws-ecs-alb-service-task
cloudposse/terraform-aws-waf
cloudposse/terraform-module-test
cloudposse/terraform-aws-vpn-connection
cloudposse/terraform-aws-elastic-beanstalk-environment
cloudposse/terraform-aws-ssm-tls-ssh-key-pair
cloudposse/terraform-aws-dynamic-subnets
cloudposse/terraform-spacelift-cloud-infrastructure-automation
cloudposse/terraform-aws-alb-ingress
cloudposse/terraform-aws-ecs-web-app
cloudposse/terraform-aws-eks-fargate-profile
cloudposse/terraform-aws-eks-node-group
cloudposse/terraform-aws-iam-policy
cloudposse/terraform-aws-eks-cluster
16 changes: 16 additions & 0 deletions migrate/migrations/20240530/repos-01
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cloudposse/terraform-aws-ec2-instance
cloudposse/terraform-aws-named-subnets
cloudposse/terraform-aws-documentdb-cluster
cloudposse/terraform-aws-cloudfront-s3-cdn
cloudposse/terraform-aws-ec2-bastion-server
cloudposse/terraform-aws-api-gateway
cloudposse/terraform-null-smtp-mail
cloudposse/terraform-aws-ssm-patch-manager
cloudposse/terraform-aws-iam-user
cloudposse/terraform-aws-vpc-peering-multi-account
cloudposse/terraform-aws-step-functions
cloudposse/terraform-aws-athena
cloudposse/terraform-aws-ecr-public
cloudposse/terraform-aws-service-quotas
cloudposse/terraform-aws-elasticache-memcached
cloudposse/terraform-aws-macie
16 changes: 16 additions & 0 deletions migrate/migrations/20240530/repos-02
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cloudposse/terraform-aws-sso
cloudposse/terraform-aws-rds-replica
cloudposse/terraform-aws-eks-spotinst-ocean-nodepool
cloudposse/terraform-aws-inspector
cloudposse/terraform-yaml-config
cloudposse/terraform-opsgenie-incident-management
cloudposse/terraform-aws-cloudwatch-events
cloudposse/terraform-aws-transit-gateway
cloudposse/terraform-aws-sns-cloudwatch-sns-alarms
cloudposse/terraform-aws-ses
cloudposse/terraform-aws-ssm-parameter-chamber-reader
cloudposse/terraform-aws-cloudformation-stack
cloudposse/terraform-aws-cloudformation-stack-set
cloudposse/terraform-aws-iam-chamber-s3-role
cloudposse/terraform-aws-iam-s3-user
cloudposse/terraform-kubernetes-tfc-cloud-agent
Loading

0 comments on commit 6eb7f84

Please sign in to comment.