-
Notifications
You must be signed in to change notification settings - Fork 322
Kloet/release single #3997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dskloetc
wants to merge
12
commits into
main
Choose a base branch
from
kloet/release-single
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Kloet/release single #3997
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b79559b
Copy rkflows/upsert-release-pr.yml
dskloetc a2e4bed
add workflow
dskloetc 1816fb1
Fake changesets for testing
dskloetc 46d7251
Add testing to PR title
dskloetc d292ef1
Change upsert workflow for testing
dskloetc dbbddb8
Rename upsert workflow for testing
dskloetc 690989f
Add quotes around CHANGESET_IGNORE_ARGS when setting GITHUB_ENV
dskloetc 9058787
Make CHANGESET_IGNORE_ARGS a single line
dskloetc 7f8ef73
debug CHANGESET_IGNORE_ARGS GITHUB_ENV
dskloetc 559f57f
copy to upsert
dskloetc f4bc330
Choose a branch name
dskloetc d66886c
stuff
dskloetc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/token-balance-adapter': minor | ||
--- | ||
|
||
testing workflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chainlink/aleno-adapter': minor | ||
--- | ||
|
||
testing workflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
args_to_ignore=() | ||
args_adapters=() | ||
|
||
if [[ -n "${1:-}" ]]; then | ||
eas_to_include="$(echo "$*" | sed -e 's/ *, */ /g' | tr ' ' '\n')" | ||
packages_to_include="$(echo "$eas_to_include" | tr ' ' '\n' | sed -e 's|.*|@chainlink/&-adapter|')" | ||
|
||
all_packages=$(yarn workspaces list --json | jq -r '.name' | grep -v '@chainlink/external-adapters-js') | ||
|
||
args_to_ignore=($(echo "$all_packages" | grep -vFf <(echo "$packages_to_include" | tr ' ' '\n') | sed -e 's|^|--ignore |')) | ||
args_adapters=($(echo "$eas_to_include" | tr ' ' '\n' | sed -e 's|^|--adapters &|')) | ||
fi | ||
|
||
export UPSTREAM_BRANCH=main | ||
yarn changeset version "${args_to_ignore[@]}" | ||
yarn generate:master-list -v | ||
yarn generate:readme -v "${args_adapters[*]}" | ||
git add MASTERLIST.md "*README.md" | ||
yarn lint-staged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
if [[ -z "${1:-}" ]]; then | ||
exit 0 | ||
fi | ||
|
||
eas_to_include="$(echo "$*" | sed -e 's/ *, */ /g' | tr ' ' '\n')" | ||
packages_to_include="$(echo "$eas_to_include" | tr ' ' '\n' | sed -e 's|.*|@chainlink/&-adapter|')" | ||
|
||
all_packages=$(yarn workspaces list --json | jq -r '.name' | grep -v '@chainlink/external-adapters-js') | ||
|
||
packages_to_ignore="$(echo "$all_packages" | grep -vFf <(echo "$packages_to_include" | tr ' ' '\n'))" | ||
|
||
echo "$packages_to_ignore" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/bin/bash -e | ||
|
||
# Run changesets | ||
yarn changeset version | ||
yarn changeset version "$@" | ||
|
||
# Recover all our changes (readmes, version bump) | ||
git stash pop | ||
git stash pop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
name: Release individual adapters | ||
|
||
# Creates PRs in external-adapters-js and infra-k8s to release individually selected adapters. | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
adapters: | ||
description: Comma-separated list of adapter names to release | ||
required: true | ||
|
||
jobs: | ||
consume-changesets: | ||
name: Upsert Release PR | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
UPSTREAM_BRANCH: 'main' | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits | ||
fetch-depth: 0 | ||
# We install only the changesets tool so we can do the mock changesets before installing dependencies, | ||
# as the setup action will only build the files relevant to the changed adapters | ||
- name: Install changesets tool | ||
run: | | ||
yarn add @changesets/cli@$(jq -r '.devDependencies."@changesets/cli"' package.json) | ||
- name: Configure git | ||
shell: bash | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "github-actions[bot]@users.noreply.github.com" | ||
- name: Set CHANGESET_IGNORE_ARGS env var | ||
run: | | ||
CHANGESET_IGNORE_ARGS="$(.github/scripts/packages-to-ignore.sh ${{ github.event.inputs.adapters }} | sed -e 's/^/--ignore /' | tr '\n' ' ')" | ||
echo "$CHANGESET_IGNORE_ARGS" | ||
echo "CHANGESET_IGNORE_ARGS=$CHANGESET_IGNORE_ARGS" >> $GITHUB_ENV | ||
cat $GITHUB_ENV | ||
- name: Temporarily calculate changesets to generate readmes with proper versions | ||
run: | | ||
# Get from output of previous step: | ||
PACKAGES_TO_IGNORE="${{ env.packages_to_ignore }}" | ||
yarn changeset version $CHANGESET_IGNORE_ARGS | ||
git add -A | ||
git commit -m "Changesets mock" | ||
- name: Set up and install dependencies | ||
uses: ./.github/actions/setup | ||
with: | ||
build-all: 'true' | ||
- name: Increase monorepo version | ||
run: | | ||
BUMPED_VERSION=$(jq -r '.version | split(".")[1] | tonumber | . + 1 | tostring | "1." + . + ".0"' package.json) | ||
jq ".version = \"$BUMPED_VERSION\"" package.json > package.tmp.json | ||
mv package.tmp.json package.json | ||
echo "BUMPED_VERSION=$BUMPED_VERSION" >> $GITHUB_ENV | ||
- name: Generate documentation | ||
run: | | ||
yarn generate:master-list -v | ||
yarn generate:readme -v | ||
- name: Undo temporary changesets and commit docs | ||
run: | | ||
git stash | ||
git reset HEAD^ --hard | ||
git stash pop | ||
- name: Commit docs | ||
run: | | ||
git add MASTERLIST.md | ||
git add "*README.md" | ||
yarn lint-staged | ||
- name: Stash changes for changesets action to pick up in custom script | ||
run: | | ||
git stash | ||
- name: Create Release Pull Request | ||
uses: smartcontractkit/.github/actions/signed-commits@4b7aa1d5b60f0d5704400a1d2b192905ad386e6c # changesets-signed-commits@1.2.4 | ||
with: | ||
# This version command is not only necessary because of yarn pnp, but because the changeset action | ||
# performs git resets and we want to keep those changes, so we stash and then pop them here. | ||
# All the previous steps would technically make more sense in the script itself, but we | ||
# keep them as separate ones so it's easier to see them from the github UI to debug. | ||
version: ./.github/scripts/run-changesets.sh ${{ env.CHANGESET_IGNORE_ARGS }} | ||
title: 'testing Release ${{ env.BUMPED_VERSION }}' | ||
commit: 'testing Release ${{ env.BUMPED_VERSION }}' | ||
- name: Tag changesets commit | ||
run: | | ||
# Delete the tags if they already exist (ignore errors if they don't) | ||
#git tag -d "v$BUMPED_VERSION" || true | ||
#git push --delete origin "v$BUMPED_VERSION" || true | ||
#git tag "v$BUMPED_VERSION" | ||
#git push origin "v$BUMPED_VERSION" | ||
# Because the workflows won't run and we technically don't need them for this autogenerated PR, | ||
# we manually skip all the required checks by using the GitHub API directly. | ||
- name: Skip required checks manually | ||
run: | | ||
COMMIT_SHA=$(git rev-parse HEAD) | ||
./.github/scripts/skip-check.sh $COMMIT_SHA "Adapter changes accompanied by a changeset" | ||
./.github/scripts/skip-check.sh $COMMIT_SHA "Documentation generation test" | ||
./.github/scripts/skip-check.sh $COMMIT_SHA "Install and verify dependencies" | ||
./.github/scripts/skip-check.sh $COMMIT_SHA "Run integration tests for changed adapters" | ||
./.github/scripts/skip-check.sh $COMMIT_SHA "Run linters and formatters" | ||
./.github/scripts/skip-check.sh $COMMIT_SHA "Run unit tests for changed adapters" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { exec, test } from 'shelljs' | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as ini from 'ini'; | ||
import commandLineArgs from 'command-line-args' | ||
import commandLineUsage from 'command-line-usage' | ||
import { getWorkspaceAdapters } from '../workspace' | ||
|
||
export async function main(): Promise<void | string> { | ||
try { | ||
// Define CLI options | ||
const commandLineOptions = [ | ||
{ | ||
name: 'adapters', | ||
multiple: true, | ||
defaultOption: true, | ||
description: 'Adapters to include in release PRs', | ||
}, | ||
{ name: 'help', alias: 'h', type: Boolean, description: 'Display usage guide' }, | ||
] | ||
const options = commandLineArgs(commandLineOptions) | ||
|
||
// Generate usage guide | ||
if (options.help) { | ||
const usage = commandLineUsage([ | ||
{ | ||
header: 'Release PR creation script', | ||
content: | ||
'This script is run from the root of the external-adapter-js/ repo to create a PR in this repo and another PR in infra-k8s to facilitate the release of a subset of adapters.', | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: commandLineOptions, | ||
}, | ||
{ | ||
content: | ||
'Source code: {underline https://github.com/smartcontractkit/external-adapters-\njs/packages/scripts/src/create-release-prs', | ||
}, | ||
]) | ||
console.log(usage) | ||
return | ||
} | ||
|
||
const allAdapters = getWorkspaceAdapters() | ||
const adaptersToIgnore = [] | ||
if (options.adapters && options.adapters.length > 0) { | ||
adaptersToIgnore.push(...allAdapters.filter((a) => { | ||
return !options.adapters.includes(a.descopedName) && !options.adapters.includes(a.descopedName.replace(/-adapter$/, '')) | ||
})) | ||
} | ||
const ignoreArgs = adaptersToIgnore.map((a) => `--ignore ${a.name}`).join(' ') | ||
|
||
exec(`yarn changeset version ${ignoreArgs}`, { | ||
fatal: true, | ||
}) | ||
|
||
const awsConfigPath = path.join(process.env.HOME, '.aws', 'config') | ||
const awsConfigText = fs.readFileSync(awsConfigPath).toString() | ||
const awsConfig = ini.parse(awsConfigText) | ||
const awsProfileSdlc = awsConfig['profile sdlc'] | ||
|
||
if (!awsProfileSdlc) { | ||
throw new Error('AWS profile "sdlc" not found in ~/.aws/config') | ||
} | ||
|
||
const sdlcAccountId = | ||
|
||
const imageRepo = | ||
|
||
console.log('dskloetx awsConfig', awsConfig['profile sdlc']) | ||
|
||
// gh workflow run --repo smartcontractkit/infra-k8s --ref main "Infra-k8s Image Dispatcher" -F imageRepos=795953128386.dkr.ecr.us-west-2.amazonaws.com/adapters/cmeth-adapter -F gitRepo=dskloet-test-fake-repo-name | ||
|
||
/* | ||
const testOutput = exec(`yarn test ${this.integrationTestPath}`, { | ||
fatal: true, | ||
silent: true, | ||
env: { ...process.env, ...testEnvOverrides }, | ||
}).toString() | ||
*/ | ||
|
||
process.exit(0) | ||
} catch (error) { | ||
console.error({ error: error.message, stack: error.stack }) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 12 days ago
To fix this issue, add a
permissions
block specifying the minimal required permissions for the job or workflow. The block can be added either at the workflow level (top-level, beforejobs:
) to apply to all jobs, or within each individual job if some jobs need broader permissions than others. For this workflow, since all operations are within a single job (consume-changesets
), add the block to that job. As a minimum, setcontents: write
since the job performs git commits and push operations, and may require write access to repository contents. If the job interacts with issues or pull requests (as seems likely due to the creation of release PRs), also considerpull-requests: write
. If only reading contents is required, specifycontents: read
. Adjust permissions according to the tasks performed—here,contents: write
andpull-requests: write
are suitable starting points.Specifically:
.github/workflows/release-individual.yml
, in thejobs.consume-changesets
block (preferably immediately belowname: Upsert Release PR
, but any location within the job is valid).