Skip to content

Commit

Permalink
Enforce vscode marketplace compatible versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Apr 3, 2024
1 parent b0e1b8d commit afd999f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ stdout
stopendy
suboption
suboptions
subshells
sysninja
taskfile
testenv
Expand Down Expand Up @@ -224,8 +225,8 @@ uuidv
uuidv4
varInfiles
venvs
vscodeignore
vnet
vscodeignore
vscoss
vsix
vyos
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ jobs:
steps:

- uses: actions/checkout@v4
with:
fetch-depth: 0 # we need tags for dynamic versioning
show-progress: false

# https://github.com/marketplace/actions/setup-wsl
- name: Activate WSL
Expand Down Expand Up @@ -263,7 +266,7 @@ jobs:
if: ${{ matrix.name == 'test' }}
uses: actions/upload-artifact@v4
with:
name: ansible-extension-build-${{ github.event.number || github.ref_name }}.vsix
name: ansible-extension-build-${{ github.event.number || github.ref_name }}.zip
path: ansible-*.vsix
if-no-files-found: error
retention-days: 90
Expand Down
17 changes: 1 addition & 16 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ vars:
sh: bash -c 'if [[ "$OSTYPE" == "linux-gnu"* ]] && command -v xvfb-run >/dev/null; then echo "$(command -v xvfb-run) --auto-servernum -e out/log/xvfb.log"; fi'
tasks:
default:
vars:
VERSION:
sh: node -p "require('./package.json').version"
desc: Run most commands
deps:
- install
- lint
- package
cmds:
- echo {{.TASK}}
- echo Done {{.VERSION}}!
setup:
desc: Install dependencies
deps:
Expand Down Expand Up @@ -161,9 +157,6 @@ tasks:
- npm run unit-tests
interactive: true
package:
vars:
VERSION:
sh: node -p "require('./package.json').version"
desc: Package extension
deps:
- build
Expand All @@ -179,15 +172,7 @@ tasks:
generates:
- "*.vsix"
cmds:
- rm -f *.vsix
- yarn run webpack
# --pre-release not supported until we do VS Code >=1.63
# --no-dependencies and --no-yarn needed due to https://github.com/microsoft/vscode-vsce/issues/439
- yarn run vsce package --pre-release --no-dependencies --no-git-tag-version --no-update-package-json {{.VERSION}}
# Using zipinfo instead of `npx vsce ls` due to https://github.com/microsoft/vscode-vsce/issues/517
- zipinfo -1 *.vsix
- tools/dirty.sh
- ls -la *.vsix
- ./tools/package.sh
silent: true
pr:
desc: Opens a pull request using gh
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vscode/test-electron": "^2.3.9",
"@vscode/vsce": "^2.23.0",
"@vscode/vsce": "^2.24.0",
"axios": "^1.6.7",
"chai": "^4.4.1",
"copyfiles": "^2.4.1",
Expand Down Expand Up @@ -832,7 +832,7 @@
"scripts": {
"compile": "tsc -b && copyfiles -u 4 'node_modules/@ansible/ansible-language-server/out/server/**/*' out",
"compile-withserver": "tsc -b && tsc -p ../ansible-language-server --outDir out/server && ln -f -s ${PWD}/../ansible-language-server/node_modules out/server/node_modules",
"package": "yarn run webpack && npx vsce package",
"package": "./tools/package.sh",
"preinstall": "",
"pretest": "yarn run compile",
"unit-tests": "nyc mocha --recursive test/units",
Expand Down
18 changes: 18 additions & 0 deletions tools/get-marketplace-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Retries a vscode marketplace compatible version number to be used by
# vsce package && vsce publish. These require numeric only, X.Y.Z with ranges
# between 0-2147483647. Package allows other version numbers but publish does
# not.
#
# We used the build number in the past, but that would not allow use retrigger
# a build and might cause problems when switching from a CI to another. Thus,
# we opted for number of seconds passed between last tag and last commit. This
# should generate 0 for tagged commits and other numbers for pull requests.
set -Ee
LAST_TAG=$(git describe --tags --abbrev=0)
LAST_TAG_TIMESTAMP=$(git -P log -1 --format=%ct "${LAST_TAG}")
LAST_COMMIT_TIMESTAMP=$(git -P show --no-patch --format=%ct HEAD)
VERSION_SUFFIX="$((LAST_COMMIT_TIMESTAMP-LAST_TAG_TIMESTAMP))"
# We remove the last number from the node reported version.
VERSION_PREFIX=$(node -p "require('./package.json').version")
echo -n "${VERSION_PREFIX%.*}.${VERSION_SUFFIX}"
16 changes: 16 additions & 0 deletions tools/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -Eeuxo pipefail
# ^ capital E needed as we want to fail for subshells too.
rm -f ./*.vsix
yarn run webpack
VERSION="$(./tools/get-marketplace-version.sh)"
vsce_package_args=(--no-dependencies --no-git-tag-version --no-update-package-json)
if [[ "$VERSION" == *.0 ]]; then
vsce_package_args+=("--pre-release")
fi
# --no-dependencies and --no-yarn needed due to https://github.com/microsoft/vscode-vsce/issues/439
yarn run vsce package "${vsce_package_args[@]}" "${VERSION}"
# Using zipinfo instead of `npx vsce ls` due to https://github.com/microsoft/vscode-vsce/issues/517
zipinfo -1 ./*.vsix > out/log/package.log
tools/dirty.sh
echo "Generated ansible-${VERSION}"
2 changes: 1 addition & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const config = {
stats: {
errorDetails: true,
moduleTrace: true,
preset: "minimal",
preset: "errors-warnings",
},
target: "node", // vscode extensions run in a Node.js-context
};
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ __metadata:
languageName: node
linkType: hard

"@vscode/vsce@npm:^2.19.0, @vscode/vsce@npm:^2.23.0, @vscode/vsce@npm:^2.24.0":
"@vscode/vsce@npm:^2.19.0, @vscode/vsce@npm:^2.24.0":
version: 2.24.0
resolution: "@vscode/vsce@npm:2.24.0"
dependencies:
Expand Down Expand Up @@ -1963,7 +1963,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": "npm:^6.21.0"
"@typescript-eslint/parser": "npm:^6.21.0"
"@vscode/test-electron": "npm:^2.3.9"
"@vscode/vsce": "npm:^2.23.0"
"@vscode/vsce": "npm:^2.24.0"
"@vscode/webview-ui-toolkit": "npm:^1.4.0"
axios: "npm:^1.6.7"
chai: "npm:^4.4.1"
Expand Down

0 comments on commit afd999f

Please sign in to comment.