Apply Version Update #712
Workflow file for this run
This file contains 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
name: Apply Version Update | |
on: | |
pull_request_review: | |
types: [ submitted, edited ] | |
permissions: | |
id-token: write | |
contents: write | |
packages: write | |
issues: write # make comment | |
pull-requests: write # open PR | |
env: | |
NODE_VERSION: 17.0.1 | |
ANCHOR_VERSION: 0.26.0 | |
SOLANA_VERSION_STABLE: 1.14.13 | |
RUST_TOOLCHAIN: stable | |
jobs: | |
dump-context: | |
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
get-changes-scope: | |
if: | | |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && | |
contains(fromJson('["OWNER", "MEMBER", "CONTRIBUTOR"]'), github.event.review.author_association) == true && | |
contains(fromJson('["approved", "commented"]'), github.event.review.state) == true | |
runs-on: ubuntu-latest | |
outputs: | |
changed-packages: ${{ steps.get-changed-package-scope.outputs.packages }} | |
num-packages: ${{ steps.get-changed-package-scope.outputs.num-packages }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: List changed files | |
uses: ./.github/actions/list-changed-files | |
id: list-changed-files | |
with: | |
pull-number: ${{ github.event.pull_request.number }} | |
# we ignore js/idl because that's an output of updating the package's rust version | |
# note: rust version updates also result in package.json changes, so multiple version updates | |
# will result in the js package also getting updated. but, i think this is ok since there | |
# haven't been any PRs to date with multiple version changes. and, in the long term, we | |
# want more granular version commands | |
exclude: '["js/idl"]' | |
# map fetched changed files to package / lang (list) | |
- name: Get scope of changed packages | |
uses: actions/github-script@v4 | |
id: get-changed-package-scope | |
with: | |
# update regexp to consider other subdirs - e.g. `rust|test|cli|<etc>` | |
script: | | |
const files = ${{ steps.list-changed-files.outputs.changed-files }} | |
const regexp = /[a-zA-Z\-]+\/(js|program)/g | |
const uniqueFilesObj = files.reduce((p, file) => { | |
const match = file.match(regexp) | |
if (match) { | |
// use first match result | |
if (!p[match[0]]) p[match[0]] = 1 | |
} | |
return p | |
}, {}) | |
const changedPackages = Array.from(Object.keys(uniqueFilesObj)) | |
core.setOutput('packages', JSON.stringify(changedPackages.map((el) => `\"${el}\"`))) | |
core.setOutput('num-packages', changedPackages.length) | |
- name: Print changed scope output | |
id: print-changed-scope-output | |
run: | | |
echo "num packages -> ${{ steps.get-changed-package-scope.outputs.num-packages }}" | |
echo "packages -> ${{ steps.get-changed-package-scope.outputs.packages }}" | |
shell: bash | |
get-version-scope: | |
if: | | |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && | |
contains(fromJson('["OWNER", "MEMBER", "CONTRIBUTOR"]'), github.event.review.author_association) == true && | |
contains(fromJson('["approved", "commented"]'), github.event.review.state) == true | |
runs-on: ubuntu-latest | |
outputs: | |
versioning: ${{ steps.parse-version-info.outputs.versioning }} | |
has-versioning: ${{ steps.parse-version-info.outputs.has-versioning }} | |
steps: | |
- uses: actions/checkout@v3 | |
# GH doesn't process or format body fields, so we do some light processing so that multiline comments will break inputs | |
- name: Process content body | |
id: process-content-body | |
env: | |
REVIEW_BODY: ${{ github.event.review.body }} | |
run: | | |
REVIEW_CONTENT=$(cat << EOF | |
$REVIEW_BODY | |
EOF | |
) | |
REVIEW_CONTENT="${REVIEW_CONTENT//\'/}" | |
REVIEW_CONTENT="${REVIEW_CONTENT//$'\n'/\\n}" | |
REVIEW_CONTENT="${REVIEW_CONTENT//$'\r'/\\r}" | |
echo "::set-output name=content::$REVIEW_CONTENT" | |
shell: bash | |
- name: Log processed content body | |
env: | |
CONTENT_BODY: ${{ steps.process-content-body.outputs.content }} | |
run: echo "$CONTENT_BODY" | |
shell: bash | |
- name: Parse version info from review | |
uses: ./.github/actions/parse-version-command | |
id: parse-version-info | |
with: | |
body: ${{ steps.process-content-body.outputs.content }} | |
update-pr-with-changes: | |
needs: [ get-changes-scope, get-version-scope ] | |
if: needs.get-version-scope.outputs.has-versioning == 'true' && needs.get-changes-scope.outputs.num-packages > 0 | |
runs-on: ubuntu-latest-16-cores | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: ./.github/actions/install-linux-build-deps | |
# - uses: ./.github/actions/install-solana | |
# with: | |
# solana_version: ${{ env.SOLANA_VERSION_STABLE }} | |
- uses: ./.github/actions/install-rust | |
with: | |
toolchain: ${{ env.RUST_TOOLCHAIN }} | |
- name: Make version changes | |
uses: ./.github/actions/make-version-changes | |
id: make-version-changes | |
with: | |
changed-packages: ${{ needs.get-changes-scope.outputs.changed-packages }} | |
versioning: ${{ needs.get-version-scope.outputs.versioning }} | |
from-branch: ${{ github.event.pull_request.head.ref }} | |
from-repository: ${{ github.event.pull_request.head.repo.full_name }} |