1
+ name : publish-QAExtension
2
+
3
+ on :
4
+ workflow_dispatch :
5
+
6
+ jobs :
7
+ publish-QAExtension :
8
+ if : " !contains(github.event.head_commit.message, '[skip ci]')"
9
+ runs-on : ubuntu-latest
10
+ steps :
11
+ - uses : actions/checkout@v4
12
+
13
+ - name : Set Node.js 20.x
14
+ uses : actions/setup-node@v4
15
+ with :
16
+ node-version : 20.x
17
+
18
+ - name : Install dependencies
19
+ run : cd blackduck-security-task && npm ci
20
+
21
+ - name : Rebuild the dist/ directory
22
+ run : cd blackduck-security-task && npm run build && npm run package
23
+
24
+ - name : Compare the expected and actual dist/ directories
25
+ run : |
26
+ cd blackduck-security-task
27
+ if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
28
+ echo "Detected uncommitted changes after build. See status below:"
29
+ git diff
30
+ exit 1
31
+ fi
32
+ id : diff
33
+
34
+ - name : versioning
35
+ id : version-update
36
+ env :
37
+ GITHUB_TOKEN : ${{ secrets.GITHUBTOKEN }}
38
+ run : |
39
+ extension_name=$(jq -r '.name' < vss-extension-dev.json)
40
+ echo "EXTENSION_NAME=$extension_name" >> $GITHUB_ENV
41
+ echo "EXTENSION NAME: "$extension_name
42
+ current_extension_version=$(jq -r '.version' < vss-extension-dev.json)
43
+ echo "CURRENT_VERSION=$current_extension_version" >> $GITHUB_ENV
44
+ echo "CURRENT QAEXTENSION VERSION: " $current_extension_version
45
+ previous_published_qaextension_version=$(grep 'published_qaextension_version' extension_version.txt | cut -d '=' -f 2)
46
+ echo "PREVIOUS PUBLISHED QAEXTENSION VERSION: " $previous_published_qaextension_version
47
+ previous_major=$(echo $previous_published_qaextension_version | awk -F. '{print $1}')
48
+ previous_minor=$(echo $previous_published_qaextension_version | awk -F. '{print $2}')
49
+ previous_patch=$(echo $previous_published_qaextension_version | awk -F. '{print $3}')
50
+ current_major=$(echo $current_extension_version | awk -F. '{print $1}')
51
+ current_minor=$(echo $current_extension_version | awk -F. '{print $2}')
52
+ if [ "$previous_major" -eq "$current_major" ] && [ "$previous_minor" -eq "$current_minor" ]; then
53
+ current_patch=$((previous_patch+1))
54
+ new_version=$current_major.$current_minor.$current_patch
55
+ echo "Updating extension version to: ${new_version}"
56
+ else
57
+ new_version=$current_extension_version
58
+ echo "Extension version will not be updating automatically. Current version: ${new_version}"
59
+ fi
60
+ echo "Updating vss-extension-dev.json with the new version: ${new_version}"
61
+ 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
62
+ echo "Updated vss-extension-dev.json file"
63
+ cat vss-extension-dev.json
64
+ echo
65
+
66
+ echo "Updating extension_version.txt with the new version: ${new_version}"
67
+ sed -i "s/published_qaextension_version=.*/published_qaextension_version=$new_version/" extension_version.txt
68
+ cat extension_version.txt
69
+ echo
70
+ echo "Updated extension_version.txt file"
71
+
72
+ echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
73
+ - name : publish-QAExtension
74
+ id : publish-qaextension
75
+ if : ${{ steps.version-update.conclusion == 'success' }}
76
+ env :
77
+ PUBLISHER_NAME : ${{ secrets.PUBLISHER_NAME }}
78
+ ORGANIZATION_NAME : ${{ secrets.ORG_NAME }}
79
+ USER_TOKEN : ${{ secrets.USER_TOKEN }} # personal_access_token of azure devops account
80
+ run : |
81
+ vss_extension_dev=$(cat vss-extension-dev.json)
82
+ extension_name=$(echo $vss_extension_dev | jq -r '.name' )
83
+ echo "Extension Name:" $extension_name
84
+ extension_version=$(echo $vss_extension_dev | jq -r '.version')
85
+ echo "Extension Version:" $extension_version
86
+ echo "Installing tfx-cli..."
87
+ npm i -g tfx-cli
88
+ echo "Creating extension $extension_name with version $extension_version"
89
+ npx tfx-cli extension create --manifest-globs vss-extension-dev.json
90
+ echo "Extension $extension_name created successfully!"
91
+ echo "Publishing extension $extension_name with version $extension_version"
92
+ tfx extension publish --publisher ${PUBLISHER_NAME} --manifest-globs vss-extension-dev.json --token ${USER_TOKEN} | tee tfx_output.log
93
+ publish_exit_code=${PIPESTATUS[0]}
94
+ if [ $publish_exit_code -eq 0 ]; then
95
+ echo "Extension $extension_name with version $extension_version published successfully!"
96
+ else
97
+ echo "Failed to publish the extension $extension_name with version $extension_version."
98
+ exit 1
99
+ fi
100
+
101
+
102
+ - name : update extension version in file
103
+ id : update-extension-version
104
+ if : ${{ steps.publish-qaextension.conclusion == 'success' }}
105
+ env :
106
+ GITHUB_TOKEN : ${{ secrets.GITHUBTOKEN }}
107
+ run : |
108
+ echo "Updating extension version in vss-extension-dev.json & extension_version.txt file"
109
+ git config --local user.name "$(git log -n 1 --pretty=format:%an)"
110
+ git config --local user.email "$(git log -n 1 --pretty=format:%ae)"
111
+ git checkout -b qaextension_version_update
112
+ git add vss-extension-dev.json extension_version.txt
113
+ git commit -m "update extension version to ${{ env.NEW_VERSION }} [skip ci]"
114
+ git push origin qaextension_version_update
115
+ echo gh --version
116
+ 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 }}"
117
+ gh pr merge --squash --subject "Extension version upgrade to ${{ env.NEW_VERSION }} [skip ci]" --delete-branch
118
+
119
+ - name : Upload Artifact
120
+ uses : actions/upload-artifact@v4
121
+ with :
122
+ name : ${{ env.EXTENSION_NAME }}-${{ env.NEW_VERSION }}.vsix
123
+ path : " *.vsix"
0 commit comments