Skip to content

Commit

Permalink
Label creation automation
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Jun 22, 2023
1 parent 8fb3588 commit 79c2520
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 27 deletions.
76 changes: 49 additions & 27 deletions .github/workflows/os-increment-plugin-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,7 @@ jobs:
fail-fast: false
matrix:
entry:
- {repo: alerting}
- {repo: anomaly-detection}
- {repo: asynchronous-search}
- {repo: common-utils}
- {repo: cross-cluster-replication}
- {repo: geospatial}
- {repo: index-management}
- {repo: job-scheduler}
- {repo: k-NN}
- {repo: neural-search}
- {repo: ml-commons}
- {repo: notifications, path: notifications}
- {repo: observability}
- {repo: performance-analyzer}
- {repo: performance-analyzer-rca}
- {repo: reporting}
- {repo: security}
- {repo: security-analytics}
- {repo: sql}
branch:
- '1.3'
- 2.x
Expand All @@ -65,11 +47,54 @@ jobs:
echo "OPENSEARCH_VERSION_NUMBER=$OPENSEARCH_VERSION" >> $GITHUB_ENV
OPENSEARCH_VERSION=$OPENSEARCH_VERSION-SNAPSHOT
echo "OPENSEARCH_VERSION=$OPENSEARCH_VERSION" >> $GITHUB_ENV

Check failure on line 50 in .github/workflows/os-increment-plugin-versions.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

50:1 [trailing-spaces] trailing spaces
- name: Check out plugin repo
uses: actions/checkout@v3
with:
repository: opensearch-project/${{ matrix.entry.repo }}
repository: prudhvigodithi/${{ matrix.entry.repo }}
ref: ${{ matrix.branch }}

Check failure on line 56 in .github/workflows/os-increment-plugin-versions.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

56:1 [trailing-spaces] trailing spaces
- name: Get owner and repo
id: repo_info
run: |
echo "OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV
echo "REPO=${{ github.event.repository.name }}" >> $GITHUB_ENV
- name: Check if label exists
id: check_label
uses: actions/github-script@v6
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
result-encoding: string
script: |
const { data: labels } = await github.rest.issues.listLabelsForRepo({
owner: process.env.OWNER,
repo: process.env.REPO,
per_page: 100
});
const labelFound = labels.some(label => label.name === 'v${{ env.OPENSEARCH_VERSION_NUMBER }}');
console.log(labelFound);
return labelFound
- name: Create label
if: ${{ steps.check_label.outputs.result != 'true' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
const newLabel = {
owner: process.env.OWNER,
repo: process.env.REPO,
name: "v${{ env.OPENSEARCH_VERSION_NUMBER }}",
color: randomColor,
description: "v${{ env.OPENSEARCH_VERSION_NUMBER }}"
};
await github.rest.issues.createLabel(newLabel);
- name: Increment Version in ${{ matrix.entry.repo }}
run: |
echo "OpenSearch Core repo version on branch ${{ matrix.branch }} is ${{ env.OPENSEARCH_VERSION_NUMBER }}"
Expand All @@ -78,18 +103,12 @@ jobs:
cd ${{ matrix.entry.path }}
fi
./gradlew updateVersion -DnewVersion=${{ env.OPENSEARCH_VERSION }}
- name: GitHub App token
id: github_app_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
installation_id: 22958780
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ steps.github_app_token.outputs.token }}
token: ${{ secrets.GITHUB_TOKEN }}
committer: opensearch-ci-bot <[email protected]>
author: opensearch-ci-bot <[email protected]>
commit-message: |
Expand All @@ -99,9 +118,12 @@ jobs:
delete-branch: true
branch: create-pull-request/${{ env.OPENSEARCH_VERSION }}
title: '[AUTO] Increment version to ${{ env.OPENSEARCH_VERSION }}'
labels: |
v${{ env.OPENSEARCH_VERSION_NUMBER }}
body: |
- Incremented version to **${{ env.OPENSEARCH_VERSION }}**.
- name: Check outputs
run: |-
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

Check failure on line 129 in .github/workflows/os-increment-plugin-versions.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

129:5 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 129 in .github/workflows/os-increment-plugin-versions.yml

View workflow job for this annotation

GitHub Actions / yaml-lint

129:1 [trailing-spaces] trailing spaces
33 changes: 33 additions & 0 deletions .github/workflows/osd-increment-plugin-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
- name: Bootstrap and Version Increment
run: |
DASHBOARD_VERSION=$(node -p "require('./OpenSearch-Dashboards/package.json').version")
echo "DASHBOARD_VERSION=$DASHBOARD_VERSION" >> $GITHUB_ENV
cd OpenSearch-Dashboards/plugins/${{ matrix.entry.repo }}
if [ ${{ matrix.entry.path }} ]; then
yarn osd bootstrap
Expand Down Expand Up @@ -101,6 +102,36 @@ jobs:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
installation_id: 22958780
- name: Check if label exists
id: check_label
uses: actions/github-script@v6
with:
github-token: ${{ steps.github_app_token.outputs.token }}
result-encoding: string
script: |
const { data: labels } = await github.rest.issues.listLabelsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
const labelFound = labels.some(label => label.name === 'v${{ env.DASHBOARD_VERSION }}');
console.log(labelFound);
return labelFound
- name: Create label
if: ${{ steps.check_label.outputs.result != 'true' }}
uses: actions/github-script@v6
with:
github-token: ${{ steps.github_app_token.outputs.token }}
script: |
const randomColor = Math.floor(Math.random() * 16777215).toString(16);
const newLabel = {
owner: context.repo.owner,
repo: context.repo.repo,
name: "v${{ env.DASHBOARD_VERSION }}",
color: randomColor,
description: "v${{ env.DASHBOARD_VERSION }}"
};
await github.rest.issues.createLabel(newLabel);
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
Expand All @@ -115,6 +146,8 @@ jobs:
delete-branch: true
branch: create-pull-request/${{ env.OSD_PLUGIN_VERSION }}
title: '[AUTO] Increment version to ${{ env.OSD_PLUGIN_VERSION }}'
labels: |
v${{ env.DASHBOARD_VERSION }}
body: |
- Incremented version to **${{ env.OSD_PLUGIN_VERSION }}**.
path: 'OpenSearch-Dashboards/plugins/${{ matrix.entry.repo }}'
Expand Down

0 comments on commit 79c2520

Please sign in to comment.