Skip to content

Commit

Permalink
Merge branch 'main' into feat/parser
Browse files Browse the repository at this point in the history
  • Loading branch information
am29d committed Mar 7, 2024
2 parents d81445d + d18ffde commit a9f5d79
Show file tree
Hide file tree
Showing 230 changed files with 8,973 additions and 7,050 deletions.
21 changes: 11 additions & 10 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/blob/v0.212.0/containers/javascript-node/.devcontainer/base.Dockerfile
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT="18-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node@sha256:4dbf8b626669df834ca18dbe4b0dc49fcd521b1e0c59b1e56ba47abb39364e2c

# This section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends bash-completion
# Install fnm to manage Node.js versions
RUN curl -fsSL https://fnm.vercel.app/install -o /tmp/install \
&& chmod a+x /tmp/install \
&& /tmp/install \
&& rm /tmp/install

RUN wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip \
&& unzip aws-sam-cli-linux-x86_64.zip -d sam-installation \
&& sudo ./sam-installation/install \
&& rm -rf sam-installation aws-sam-cli-linux-*
# Install AWS SAM CLI
RUN curl -LO https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip \
&& unzip -q aws-sam-cli-linux-x86_64.zip -d sam-installation \
&& sudo ./sam-installation/install \
&& rm -rf sam-installation aws-sam-cli-linux-*
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": {
"VARIANT": "18-bullseye"
"VARIANT": "20-bullseye"
}
},
"customizations": {
// Add the ids of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"firsttris.vscode-jest-runner",
"amazonwebservices.aws-toolkit-vscode"
"firsttris.vscode-jest-runner"
],
"vscode": {
"git.enableCommitSigning": true
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

* @aws-powertools/lambda-typescript-core
* @aws-powertools/lambda-typescript-core @aws-powertools/core
8 changes: 4 additions & 4 deletions .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Cached Node Modules'
description: 'A simple action to cache node_modules or install them if they are not cached'
inputs:
nodeVersion: # id of input
nodeVersion: # id of input
description: 'Node.js version to use in the cache key'
default: '18'
default: '20'
build:
description: 'Whether to build the packages or not'
default: 'true'
Expand All @@ -15,11 +15,12 @@ runs:
using: "composite"
steps:
- name: Install npm
# We need to keep this npm version until we drop Node.js 16 support because Node.js 16 doesn't support npm 10
run: npm i -g npm@next-9
shell: bash
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: '**/node_modules'
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
Expand All @@ -44,6 +45,5 @@ runs:
npm run build -w packages/parameters & \
npm run build -w packages/idempotency & \
npm run build -w packages/batch & \
npm run build -w packages/parser & \
npm run build -w packages/testing
shell: bash
92 changes: 92 additions & 0 deletions .github/actions/create-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: "Create PR custom action"
description: "Create a PR and a temporary branch, close duplicates"

# PROCESS
#
# 1. Setup git client using Powertools for AWS Lambda bot username
# 2. Pushes staged files to a temporary branch
# 3. Creates a PR from temporary branch against a target branch (typically trunk: develop, main, etc.)
# 4. Searches for duplicate PRs with the same title
# 5. If duplicates are found, link to the most recent one, close and delete their branches so we keep a single PR
# 6. In the event of failure, we delete the now orphaned branch (if any), and propagate the failure

# REQUIREMENTS
# You need to enable "Allow GitHub Actions to create and approve pull requests" in your repository settings
# You need to have "skip-changelog" label in your repository to skip changelog generation.

# USAGE
#
# - name: Create PR
# id: create-pr
# uses: ./.github/actions/create-pr
# with:
# files: "CHANGELOG.md"
# temp_branch_prefix: "ci-changelog"
# pull_request_title: "chore(ci): changelog rebuild"
# github_token: ${{ secrets.GITHUB_TOKEN }}
# - name: Step to demonstrate how to access outputs (no need for this)
# run: |
# echo "PR number: ${PR_ID}"
# echo "Branch: ${BRANCH}"
# env:
# PR_ID: ${{ steps.create-pr.outputs.pull_request_id}}
# BRANCH: ${{ steps.create-pr.outputs.temp_branch}}

inputs:
files:
description: "Files to add separated by space"
required: true
temp_branch_prefix:
description: "Prefix for temporary git branch to be created, e.g, ci-docs"
required: true
pull_request_title:
description: "Pull Request title to use"
required: true
github_token:
description: "GitHub token for GitHub CLI"
required: true
target_branch:
description: "Branch to target when creating a PR against (main, by default)"
required: false
default: main

outputs:
pull_request_id:
description: "Pull request ID created"
value: ${{ steps.create-pr.outputs.pull_request_id }}
temp_branch:
description: "Temporary branch created with staged changed"
value: ${{ steps.create-pr.outputs.temp_branch }}

runs:
using: "composite"
steps:
- id: adjust-path
run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- id: setup-git
name: Git client setup and refresh tip
run: |
git config --global user.name 'aws-powertools-bot'
git config --global user.email '[email protected]'
git config pull.rebase true
git config remote.origin.url >&-
shell: bash
- id: create-pr
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: create_pr_for_staged_changes.sh "${FILES}"
env:
FILES: ${{ inputs.files }}
TEMP_BRANCH_PREFIX: ${{ inputs.temp_branch_prefix }}
PR_TITLE: ${{ inputs.pull_request_title }}
BASE_BRANCH: ${{ inputs.target_branch }}
GH_TOKEN: ${{ inputs.github_token }}
shell: bash
- id: cleanup
name: Cleanup orphaned branch
if: failure()
run: git push origin --delete "${TEMP_BRANCH_PREFIX}-${GITHUB_RUN_ID}" || echo "Must have failed before creating temporary branch; no cleanup needed."
env:
TEMP_BRANCH_PREFIX: ${{ inputs.temp_branch_prefix }}
GITHUB_RUN_ID: ${{ github.run_id }}
shell: bash
148 changes: 148 additions & 0 deletions .github/actions/create-pr/create_pr_for_staged_changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash
set -uo pipefail # prevent accessing unset env vars, prevent masking pipeline errors to the next command

#docs
#title :create_pr_for_staged_changes.sh
#description :This script will create a PR for staged changes, detect and close duplicate PRs. All PRs will be omitted from Release Notes and Changelogs
#author :@heitorlessa
#date :May 8th 2023
#version :0.1
#usage :bash create_pr_for_staged_changes.sh {git_staged_files_or_directories_separated_by_space}
#notes :Meant to use in GitHub Actions only. Temporary branch will be named $TEMP_BRANCH_PREFIX-$GITHUB_RUN_ID
#os_version :Ubuntu 22.04.2 LTS
#required_env_vars :PR_TITLE, TEMP_BRANCH_PREFIX, GH_TOKEN
#==============================================================================

# Sets GitHub Action with error message to ease troubleshooting
function error() {
echo "::error file=${FILENAME}::$1"
exit 1
}

function debug() {
TIMESTAMP=$(date -u "+%FT%TZ") # 2023-05-10T07:53:59Z
echo ""${TIMESTAMP}" - $1"
}

function notice() {
echo "::notice file=${FILENAME}::$1"
}

function start_span() {
echo "::group::$1"
}

function end_span() {
echo "::endgroup::"
}

function has_required_config() {
start_span "Validating required config"
test -z "${TEMP_BRANCH_PREFIX}" && error "TEMP_BRANCH_PREFIX env must be set to create a PR"
test -z "${PR_TITLE}" && error "PR_TITLE env must be set"
test -z "${GH_TOKEN}" && error "GH_TOKEN env must be set for GitHub CLI"

# Default GitHub Actions Env Vars: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
debug "Are we running in GitHub Action environment?"
test -z "${GITHUB_RUN_ID}" && error "GITHUB_RUN_ID env must be set to trace Workflow Run ID back to PR"
test -z "${GITHUB_SERVER_URL}" && error "GITHUB_SERVER_URL env must be set to trace Workflow Run ID back to PR"
test -z "${GITHUB_REPOSITORY}" && error "GITHUB_REPOSITORY env must be set to trace Workflow Run ID back to PR"

debug "Config validated successfully!"
set_environment_variables
end_span
}

function set_environment_variables() {
start_span "Setting environment variables"
export readonly WORKFLOW_URL="${GITHUB_SERVER_URL}"/"${GITHUB_REPOSITORY}"/actions/runs/"${GITHUB_RUN_ID}" # e.g., heitorlessa/aws-lambda-powertools-test/actions/runs/4913570678
export readonly TEMP_BRANCH="${TEMP_BRANCH_PREFIX}"-"${GITHUB_RUN_ID}" # e.g., ci-changelog-4894658712
export readonly BASE_BRANCH="${BASE_BRANCH:-main}" # e.g., main, defaults to develop if missing
export readonly PR_BODY="This is an automated PR created from the following workflow"
export readonly FILENAME=".github/scripts/$(basename "$0")"
export readonly NO_DUPLICATES_MESSAGE="No duplicated PRs found"
export readonly SKIP_LABEL="skip-changelog"

end_span
}

function has_anything_changed() {
start_span "Validating git staged files"
HAS_ANY_SOURCE_CODE_CHANGED="$(git status --porcelain)"

test -z "${HAS_ANY_SOURCE_CODE_CHANGED}" && debug "Nothing to update; exitting early" && exit 0
end_span
}

function create_temporary_branch_with_changes() {
start_span "Creating temporary branch: "${TEMP_BRANCH}""
git checkout -b "${TEMP_BRANCH}"

debug "Committing staged files: $*"
echo "$@" | xargs -n1 git add || error "Failed to add staged changes: "$@""
git commit -m "${PR_TITLE}"

git push origin "${TEMP_BRANCH}" || error "Failed to create new temporary branch"
end_span
}

function create_pr() {
start_span "Creating PR against ${TEMP_BRANCH} branch"
# TODO: create label
NEW_PR_URL=$(gh pr create --title "${PR_TITLE}" --body "${PR_BODY}: ${WORKFLOW_URL}" --base "${BASE_BRANCH}" --label "${SKIP_LABEL}" || error "Failed to create PR") # e.g, https://github.com/aws-powertools/powertools-lambda-python/pull/13

# greedy remove any string until the last URL path, including the last '/'. https://opensource.com/article/17/6/bash-parameter-expansion
debug "Extracing PR Number from PR URL: "${NEW_PR_URL}""
NEW_PR_ID="${NEW_PR_URL##*/}" # 13
export NEW_PR_URL
export NEW_PR_ID
end_span
}

function close_duplicate_prs() {
start_span "Searching for duplicate PRs"
DUPLICATE_PRS=$(gh pr list --search "${PR_TITLE}" --json number --jq ".[] | select(.number != ${NEW_PR_ID}) | .number") # e.g, 13\n14

if [ -z "${DUPLICATE_PRS}" ]; then
debug "No duplicate PRs found"
DUPLICATE_PRS="${NO_DUPLICATES_MESSAGE}"
else
debug "Closing duplicated PRs: "${DUPLICATE_PRS}""
echo "${DUPLICATE_PRS}" | xargs -L1 gh pr close --delete-branch --comment "Superseded by #${NEW_PR_ID}"
fi

export readonly DUPLICATE_PRS
end_span
}

function report_job_output() {
start_span "Updating job outputs"
echo pull_request_id="${NEW_PR_ID}" >>"$GITHUB_OUTPUT"
echo temp_branch="${TEMP_BRANCH}" >>"$GITHUB_OUTPUT"
end_span
}

function report_summary() {
start_span "Creating job summary"
echo "### Pull request created successfully :rocket: ${NEW_PR_URL} <br/><br/> Closed duplicated PRs: ${DUPLICATE_PRS}" >>"$GITHUB_STEP_SUMMARY"

notice "PR_URL is: ${NEW_PR_URL}"
notice "PR_BRANCH is: ${TEMP_BRANCH}"
notice "PR_DUPLICATES are: ${DUPLICATE_PRS}"
end_span
}

function main() {
# Sanity check
has_anything_changed
has_required_config

create_temporary_branch_with_changes "$@"
create_pr
close_duplicate_prs

report_job_output
report_summary
}

main "$@"
2 changes: 1 addition & 1 deletion .github/boring-cyborg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ labelPRBasedOnFilePath:

##### Greetings ########################################################################################################
firstPRWelcomeComment: >
Thanks a lot for your first contribution! Please check out our [contributing guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/chore/pr_automation/CONTRIBUTING.md) and don't hesitate to ask whatever you need.
Thanks a lot for your first contribution! Please check out our [contributing guidelines](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/CONTRIBUTING.md) and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: [Invite link](https://discord.gg/B8zZKbbyET)
Expand Down
50 changes: 50 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: 2
updates:
- package-ecosystem: docker
directory: /.devcontainer
labels: [ ]
schedule:
interval: daily

- package-ecosystem: github-actions
directory: /
labels: [ ]
schedule:
interval: daily

- package-ecosystem: docker
directory: /docs
labels: [ ]
schedule:
interval: daily

- package-ecosystem: pip
directory: /docs
labels: [ ]
schedule:
interval: daily
ignore:
- dependency-name: "mike"
update-types: ["version-update:semver-major"]

- package-ecosystem: npm
directory: /
labels: [ ]
schedule:
interval: daily
versioning-strategy: increase
ignore:
- dependency-name: "@middy/core"
update-types: [ "version-update:semver-major" ]
groups:
aws-sdk:
patterns:
- "@aws-sdk/**"
- "@smithy/**"
- "aws-sdk-client-mock"
- "aws-sdk-client-mock-jest"
aws-cdk:
patterns:
- "@aws-cdk/**"
- "aws-cdk-lib"
- "aws-cdk"
Loading

0 comments on commit a9f5d79

Please sign in to comment.