Skip to content

Commit

Permalink
Merge branch 'main' into SIGINT-2282
Browse files Browse the repository at this point in the history
  • Loading branch information
siyaramblackduck authored Oct 15, 2024
2 parents 60b675e + ebde3bb commit 400a526
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 70 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: create-tag

on:
workflow_dispatch:
inputs:
TAG:
description: 'TAG'
required: true
default: ""
type: string
TAG_BODY:
description: 'TAG DESCRIPTION'
required: false
default: ""
type: string
IS_DRAFT:
description: 'CREATE AS DRAFT'
required: false
default: false
type: boolean
IS_PRERELEASE:
description: 'PRERELEASE TAG'
required: true
default: true
type: boolean
jobs:
create-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Install dependencies
run: cd blackduck-security-task && npm ci

- name: Rebuild the dist/ directory
run: cd blackduck-security-task && npm run build && npm run package

- name: Compare the expected and actual dist/ directories
run: |
cd blackduck-security-task
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

- name: replace \n
id: process_body
run: |
tag_body="${{ github.event.inputs.TAG_BODY }}"
echo "${tag_body}">>processed_body.txt
sed -i 's/\\n/\n/g' processed_body.txt
cat processed_body.txt
processed_body=$(cat processed_body.txt | tr '\n' '\n')
echo "PROCESSED_BODY<<EOF">>$GITHUB_ENV
echo "$processed_body">>$GITHUB_ENV
echo "EOF">>$GITHUB_ENV
- name: Create tag
id: create_tag
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.event.inputs.TAG }}
release_name: "BLACK DUCK EXTENSION ${{ github.event.inputs.TAG }}"
body: ${{ env.PROCESSED_BODY }}
draft: ${{ github.event.inputs.IS_DRAFT }}
prerelease: ${{ github.event.inputs.IS_PRERELEASE }}
123 changes: 123 additions & 0 deletions .github/workflows/publish-QAExtension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: publish-QAExtension

on:
workflow_dispatch:

jobs:
publish-QAExtension:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Install dependencies
run: cd blackduck-security-task && npm ci

- name: Rebuild the dist/ directory
run: cd blackduck-security-task && npm run build && npm run package

- name: Compare the expected and actual dist/ directories
run: |
cd blackduck-security-task
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

- name: versioning
id: version-update
env:
GITHUB_TOKEN: ${{ secrets.GITHUBTOKEN }}
run: |
extension_name=$(jq -r '.name' < vss-extension-dev.json)
echo "EXTENSION_NAME=$extension_name" >> $GITHUB_ENV
echo "EXTENSION NAME: "$extension_name
current_extension_version=$(jq -r '.version' < vss-extension-dev.json)
echo "CURRENT_VERSION=$current_extension_version" >> $GITHUB_ENV
echo "CURRENT QAEXTENSION VERSION: " $current_extension_version
previous_published_qaextension_version=$(grep 'published_qaextension_version' extension_version.txt | cut -d '=' -f 2)
echo "PREVIOUS PUBLISHED QAEXTENSION VERSION: " $previous_published_qaextension_version
previous_major=$(echo $previous_published_qaextension_version | awk -F. '{print $1}')
previous_minor=$(echo $previous_published_qaextension_version | awk -F. '{print $2}')
previous_patch=$(echo $previous_published_qaextension_version | awk -F. '{print $3}')
current_major=$(echo $current_extension_version | awk -F. '{print $1}')
current_minor=$(echo $current_extension_version | awk -F. '{print $2}')
if [ "$previous_major" -eq "$current_major" ] && [ "$previous_minor" -eq "$current_minor" ]; then
current_patch=$((previous_patch+1))
new_version=$current_major.$current_minor.$current_patch
echo "Updating extension version to: ${new_version}"
else
new_version=$current_extension_version
echo "Extension version will not be updating automatically. Current version: ${new_version}"
fi
echo "Updating vss-extension-dev.json with the new version: ${new_version}"
jq --arg new_version "$new_version" '.version = $new_version' vss-extension-dev.json > vss-extension-dev.json.tmp && mv vss-extension-dev.json.tmp vss-extension-dev.json
echo "Updated vss-extension-dev.json file"
cat vss-extension-dev.json
echo
echo "Updating extension_version.txt with the new version: ${new_version}"
sed -i "s/published_qaextension_version=.*/published_qaextension_version=$new_version/" extension_version.txt
cat extension_version.txt
echo
echo "Updated extension_version.txt file"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: publish-QAExtension
id: publish-qaextension
if: ${{ steps.version-update.conclusion == 'success' }}
env:
PUBLISHER_NAME: ${{ secrets.PUBLISHER_NAME }}
ORGANIZATION_NAME: ${{ secrets.ORG_NAME }}
USER_TOKEN: ${{ secrets.USER_TOKEN }} #personal_access_token of azure devops account
run: |
vss_extension_dev=$(cat vss-extension-dev.json)
extension_name=$(echo $vss_extension_dev | jq -r '.name' )
echo "Extension Name:" $extension_name
extension_version=$(echo $vss_extension_dev | jq -r '.version')
echo "Extension Version:" $extension_version
echo "Installing tfx-cli..."
npm i -g tfx-cli
echo "Creating extension $extension_name with version $extension_version"
npx tfx-cli extension create --manifest-globs vss-extension-dev.json
echo "Extension $extension_name created successfully!"
echo "Publishing extension $extension_name with version $extension_version"
tfx extension publish --publisher ${PUBLISHER_NAME} --manifest-globs vss-extension-dev.json --token ${USER_TOKEN} | tee tfx_output.log
publish_exit_code=${PIPESTATUS[0]}
if [ $publish_exit_code -eq 0 ]; then
echo "Extension $extension_name with version $extension_version published successfully!"
else
echo "Failed to publish the extension $extension_name with version $extension_version."
exit 1
fi
- name: update extension version in file
id: update-extension-version
if: ${{ steps.publish-qaextension.conclusion == 'success' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUBTOKEN }}
run: |
echo "Updating extension version in vss-extension-dev.json & extension_version.txt file"
git config --local user.name "$(git log -n 1 --pretty=format:%an)"
git config --local user.email "$(git log -n 1 --pretty=format:%ae)"
git checkout -b qaextension_version_update
git add vss-extension-dev.json extension_version.txt
git commit -m "update extension version to ${{ env.NEW_VERSION }} [skip ci]"
git push origin qaextension_version_update
echo gh --version
gh pr create --base main --head qaextension_version_update --title "Version upgrade to ${{ env.NEW_VERSION }}" --body "${{ env.EXTENSION_NAME }} version upgrade to ${{ env.NEW_VERSION }}"
gh pr merge --squash --subject "Extension version upgrade to ${{ env.NEW_VERSION }} [skip ci]" --delete-branch
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.EXTENSION_NAME }}-${{ env.NEW_VERSION }}.vsix
path: "*.vsix"
67 changes: 67 additions & 0 deletions .github/workflows/publish-blackduck-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: publish-blackduck-extension

on:
workflow_dispatch:
inputs:
isPublish:
description: 'DO YOU WANT TO PUBLISH BLACK DUCK EXTENSION TO MARKETPLACE'
required: true
default: false
type: boolean

jobs:
publish-blackduck-extension:
if: ${{ github.event.inputs.isPublish == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Compare the expected and actual dist/ directories
run: |
cd blackduck-security-task
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

- name: publish-Extension
id: publish-extension
env:
PROD_PUBLISHER_NAME: ${{ secrets.PROD_PUBLISHER_NAME }}
PROD_ORGANIZATION_NAME: ${{ secrets.PROD_ORG_NAME }}
PROD_USER_TOKEN: ${{ secrets.PROD_USER_TOKEN }} #personal_access_token of azure devops account
run: |
extension_name=$(jq -r '.name' < vss-extension.json)
echo "EXTENSION_NAME=$extension_name" >> $GITHUB_ENV
echo "EXTENSION NAME: "$extension_name
extension_version=$(jq -r '.version' < vss-extension.json)
echo "EXTENSION_VERSION=$extension_version" >> $GITHUB_ENV
echo "EXTENSION VERSION: " $extension_version
echo "Installing tfx-cli..."
npm i -g tfx-cli
echo "Creating extension $extension_name with version $extension_version"
npx tfx-cli extension create --manifest-globs vss-extension.json
echo "Extension $extension_name created successfully!"
echo "Publishing extension $extension_name with version $extension_version"
tfx extension publish --publisher ${PROD_PUBLISHER_NAME} --manifest-globs vss-extension.json --token ${PROD_USER_TOKEN} | tee tfx_output.log
publish_exit_code=${PIPESTATUS[0]}
if [ $publish_exit_code -eq 0 ]; then
echo "Extension $extension_name with version $extension_version published successfully!"
else
echo "Failed to publish the extension $extension_name with version $extension_version."
exit 1
fi
- name: Upload Artifact
uses: actions/upload-artifact@v4
if: ${{ steps.publish-extension.conclusion == 'success' }}
with:
name: ${{ env.EXTENSION_NAME }}-${{ env.EXTENSION_VERSION }}.vsix
path: "*.vsix"
101 changes: 101 additions & 0 deletions .github/workflows/upgrade-extension-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: upgrade-extension-version

on:
workflow_dispatch:
inputs:
version:
description: 'EXTENSION VERSION'
required: true
default: ""
type: string

jobs:
upgrade-extension-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Install dependencies
run: cd blackduck-security-task && npm ci

- name: Rebuild the dist/ directory
run: cd blackduck-security-task && npm run build && npm run package

- name: Compare the expected and actual dist/ directories
run: |
cd blackduck-security-task
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

- name: versioning
id: version-update
env:
GITHUB_TOKEN: ${{ secrets.GITHUBTOKEN }}
run: |
extension_name=$(jq -r '.name' < vss-extension.json)
echo "EXTENSION_NAME=$extension_name" >> $GITHUB_ENV
echo "EXTENSION NAME: "$extension_name
current_extension_version=${{ github.event.inputs.version }}
echo "CURRENT_VERSION=$current_extension_version" >> $GITHUB_ENV
echo "CURRENT EXTENSION VERSION: " $current_extension_version
current_major=$(echo $current_extension_version | awk -F. '{print $1}')
current_minor=$(echo $current_extension_version | awk -F. '{print $2}')
current_patch=$(echo $current_extension_version | awk -F. '{print $3}')
new_version=$current_extension_version
echo "Updating vss-extension.json with the new version: ${new_version}"
jq --arg new_version "$new_version" '.version = $new_version' vss-extension.json > vss-extension.json.tmp && mv vss-extension.json.tmp vss-extension.json
echo "Updated vss-extension.json file"
cat vss-extension.json
echo
echo "Updating vss-extension-dev.json with the new version: ${new_version}"
jq --arg new_version "$new_version" '.version = $new_version' vss-extension-dev.json > vss-extension-dev.json.tmp && mv vss-extension-dev.json.tmp vss-extension-dev.json
echo "Updated vss-extension-dev.json file"
cat vss-extension-dev.json
echo
cd blackduck-security-task
echo "Updating package.json with the new version: ${new_version}"
jq --arg new_version "$new_version" '.version = $new_version' package.json > package.json.tmp && mv package.json.tmp package.json
echo "Updated package.json file"
cat package.json
echo
echo "Updating package-lock.json with the new version: ${new_version}"
jq --arg new_version "$new_version" '(.version = $new_version) | (.packages[""].version = $new_version)' package-lock.json > package-lock.json.tmp && mv package-lock.json.tmp package-lock.json
echo "Updated package-lock.json file"
echo
echo "Updating task.json with the new version: ${new_version}"
jq --argjson major "$current_major" --argjson minor "$current_minor" --argjson patch "$current_patch" '(.version.Major = $major) | (.version.Minor = $minor) | (.version.Patch = $patch)' task.json > task.json.tmp && mv task.json.tmp task.json
echo "Updated task.json file"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: update extension version in file
id: update-extension-version
env:
GITHUB_TOKEN: ${{ secrets.GITHUBTOKEN }}
run: |
echo "Updating extension version in vss-extension.json, vss-extension-dev.json, extension_version.txt, package.json, package-lock.json & task.json file"
git config --local user.name "$(git log -n 1 --pretty=format:%an)"
git config --local user.email "$(git log -n 1 --pretty=format:%ae)"
git checkout -b extension_version_update
git pull origin extension_version_update --rebase || true
git add vss-extension.json vss-extension-dev.json extension_version.txt
cd blackduck-security-task
git add package.json package-lock.json task.json
git commit -m "upgrade extension version to ${{ env.NEW_VERSION }} [skip ci]"
git push origin extension_version_update --force
gh pr create --base main --head extension_version_update --title "Extension version upgrade to ${{ env.NEW_VERSION }}" --body "${{ env.EXTENSION_NAME }} version upgrade to ${{ env.NEW_VERSION }}" --fill
echo "Successful updated extension version in vss-extension.json, vss-extension-dev.json, extension_version.txt, package.json, package-lock.json & task.json file..."
2 changes: 1 addition & 1 deletion .gitlab-ci-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
paths:
- .m2/
script:
- cd blackduck-task
- cd blackduck-security-task
- npm ci
- npm run format && npm run lint && npm run build && npm run package

Expand Down
Loading

0 comments on commit 400a526

Please sign in to comment.