Skip to content

Commit

Permalink
Merge branch 'main' into rparrish/share-update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmparrish committed May 1, 2024
2 parents afc010b + 88a24e8 commit 3881998
Show file tree
Hide file tree
Showing 252 changed files with 9,242 additions and 9,028 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- stage

jobs:
dispatch-dc:
Expand All @@ -29,5 +30,8 @@ jobs:
owner: 'adobecom',
repo: 'dc',
workflow_id: 'test-milo.yml',
ref: 'main',
ref: 'stage',
inputs: {
miloBranch: '${{ github.ref_name }}'
},
})
7 changes: 4 additions & 3 deletions .github/workflows/enforce-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
steps:
- uses: yogevbd/enforce-label-action@2.1.0
with:
REQUIRED_LABELS_ANY: "verified,trivial,needs-verification"
REQUIRED_LABELS_ANY_DESCRIPTION: "PR must be labeled with 'trivial', 'needs-verification', or 'verified'"
BANNED_LABELS: "do-not-merge,duplicate,invalid,wontfix"
REQUIRED_LABELS_ANY: "verified,trivial,needs-verification,zero-impact"
REQUIRED_LABELS_ANY_DESCRIPTION: "PR must be labeled with 'trivial', 'zero-impact', 'needs-verification', or 'verified'"
BANNED_LABELS: "do not merge,duplicate,invalid,wontfix"
BANNED_LABELS_DESCRIPTION: "This PR has a banned label, if a PR is not ready or should not be merged, please close it and open a new one."
28 changes: 25 additions & 3 deletions .github/workflows/fg-sync-repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ name: Floodgate Repo Sync

on:
workflow_dispatch:
inputs:
syncBranch:
description: 'Branch to sync'
required: true
default: 'stage'
type: choice
options:
- 'stage'
- 'main'

jobs:
build:
Expand All @@ -20,27 +29,40 @@ jobs:
uses: actions/checkout@v2
with:
persist-credentials: false
ref: ${{ inputs.syncBranch }}

- name: Clone Floodgate Repository
- name: Clone Floodgate Repository and Checkout Selected Branch
run: |
git clone https://github.com/adobecom/milo-pink.git ../milo-pink
cd ../milo-pink
git checkout $FG_SYNC_BRANCH
echo "milo-pink branch"
git branch
cd ../milo
echo "milo branch"
git branch
env:
FG_SYNC_BRANCH: ${{ inputs.syncBranch }}

- name: Overwrite floodgate repo files with latest from source repo
run: |
rsync -av --exclude='fstab.yaml' --exclude='.github' --exclude='.git' --exclude='.idea' ./ ../milo-pink/
rsync -av --exclude='fstab.yaml' --exclude='.github' --exclude='.kodiak' --exclude='.git' --exclude='.idea' --exclude='.husky' --exclude='.vscode' --exclude='tools/sidekick/config.json' ./ ../milo-pink/
- name: Commit and Push Changes to Floodgate Repository
run: |
cd ../milo-pink
echo "milo-pink branch"
git branch
git config user.email "$FG_SYNC_BOT_EMAIL"
git config user.name "$FG_SYNC_BOT_NAME"
git status
git remote set-url origin https://oauth2:$GITHUB_TOKEN@github.com/adobecom/milo-pink.git
git remote -v
git add .
git commit -m "Syncing milo to milo-pink"
git push origin main --force
git push origin $FG_SYNC_BRANCH --force
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
FG_SYNC_BOT_EMAIL: ${{ secrets.FG_SYNC_BOT_EMAIL }}
FG_SYNC_BOT_NAME: ${{ secrets.FG_SYNC_BOT_NAME }}
FG_SYNC_BRANCH: ${{ inputs.syncBranch }}
25 changes: 25 additions & 0 deletions .github/workflows/localWorkflowConfigs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Those env variables are set by an github action automatically
// For local testing, you should test on your fork.
const owner = process.env.REPO_OWNER || ''; // example owner: adobecom
const repo = process.env.REPO_NAME || ''; // example repo name: milo
const auth = process.env.GH_TOKEN || ''; // https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

const getLocalConfigs = () => {
if (!owner || !repo || !auth) {
throw new Error(`Create a .env file on the root of the project with credentials.
Then run: node --env-file=.env .github/workflows/update-ims.js`);
}

const { Octokit } = require('@octokit/rest');
return {
github: { rest: new Octokit({ auth: process.env.GH_TOKEN }) },
context: {
repo: {
owner,
repo,
},
},
};
};

module.exports = getLocalConfigs;
19 changes: 19 additions & 0 deletions .github/workflows/mark-stale-prs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Close stale pull requests"
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label.'
close-pr-message: 'Closing this PR due to inactivity.'
days-before-stale: 7
days-before-close: 7
exempt-pr-labels: 'Ready for Stage'
operations-per-run: 100
133 changes: 133 additions & 0 deletions .github/workflows/pr-reminders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Run from the root of the project for local testing: node --env-file=.env .github/workflows/pr-reminders.js

const main = async ({ github, context }) => {
const comment = async ({ pr, message, comments }) => {
if (comments.some((c) => c.body.includes(message))) {
console.log(
`PR #${pr.number} Comment exists. Commenting skipped... ${message}`
);
return;
}
process.env.LOCAL_RUN
? console.log(
`PR #${pr.number} Local execution commenting SKIPPED message: ${message}`
)
: await github.rest.issues
.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: message,
})
.then(() => console.log(`PR #${pr.number} Commented: ${message}`))
.catch(console.error);
};

const getLatestChecks = async ({ pr }) => {
const { data: checks } = await github.rest.checks
.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: pr.head.sha,
})
.catch((error) => {
console.error(error);
return { data: { check_runs: [] } };
});
const checksByName = checks.check_runs.reduce((map, check) => {
if (
!map.has(check.name) ||
new Date(map.get(check.name).completed_at) <
new Date(check.completed_at)
) {
map.set(check.name, check);
}
return map;
}, new Map());
return Array.from(checksByName.values());
};

try {
const { data: openPRs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});

for await (const pr of openPRs) {
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});

if (labels.some(({ name } = {}) => name === 'Ready for Stage' || name === 'Stale')) {
console.log(
`PR #${pr.number} has the 'Ready for Stage' or 'Stale' label. Skipping...`
);
continue;
}

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});

const latestChecks = await getLatestChecks({ github, context, pr });
if (latestChecks.some((check) => check.conclusion === 'failure')) {
comment({
pr,
comments,
message:
'This pull request is not passing all required checks. Please see [this discussion](https://github.com/orgs/adobecom/discussions/997) for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.',
});
continue;
}

const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});

if (reviews.some((review) => review.state === 'CHANGES_REQUESTED')) {
console.log(`PR #${pr.number} has changes requested. Skipping...`);
continue;
}

if (reviews.filter((review) => review.state === 'APPROVED').length < 2) {
console.log(`PR #${pr.number} has less than 2 approvals. Skipping...`);
continue;
}

if(labels.some(({ name } = {}) => name === 'needs-verification')) {
comment({
pr,
comments,
message: 'This PR is currently in the `needs-verification` state. Please assign a QA engineer to verify the changes.'
})
continue;
}

comment({
pr,
comments,
message:
'Reminder to set the `Ready for Stage` label - to queue this to get merged to stage & production.',
});
}
} catch (error) {
console.error(error);
}
};

if (process.env.LOCAL_RUN) {
const { github, context } = require('./localWorkflowConfigs.js')();
main({
github,
context,
});
}

module.exports = main;
23 changes: 23 additions & 0 deletions .github/workflows/pr-reminders.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PR Reminders

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1

- name: Remind PR initiators
uses: actions/github-script@v7.0.1
with:
script: |
const main = require('./.github/workflows/pr-reminders.js')
main({ github, context })
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/update-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Update dependencies

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1

- name: Update file and create PR if needed
uses: actions/github-script@v7.0.1
with:
script: |
const updateDependency = require('./.github/workflows/update-script.js')
updateDependency({
github,
context,
title: '[AUTOMATED-PR] Update imslib.min.js dependency',
path: 'https://auth.services.adobe.com/imslib/imslib.min.js',
branch: 'update-imslib',
scriptPath: './libs/deps/imslib.min.js'
})
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit 3881998

Please sign in to comment.