Skip to content

Modernize CI #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 118 additions & 128 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ on:
branches:
- master
paths-ignore:
- '*.md'
- '**/*.md'
- "docs/**"
- ".vscode/**"
- ".github/**"
- "*.md"
- "**/*.md"
pull_request:
branches:
- master
Expand All @@ -19,139 +22,126 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-latest]
outputs:
name: ${{ steps.set-version.outputs.name }}
version: ${{ steps.set-version.outputs.version }}
taggedbranch: ${{ steps.find-branch.outputs.taggedbranch }}
steps:
- uses: actions/checkout@v4
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set an output
id: set-version
if: runner.os == 'Linux'
run: |
set -x
VERSION=$(jq -r '.version' package.json | cut -d- -f1)
[ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/}
CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d')
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
echo ::set-output name=changelog::$CHANGELOG
git tag -l | cat
[ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" | sort -nt. -k4 2>/dev/null | tail -1 | cut -d. -f4)+1))
[ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev.${{ github.event.pull_request.number }}
echo ::set-output name=version::$VERSION
NAME=$(jq -r '.name' package.json)-$VERSION
echo ::set-output name=name::$NAME
tmp=$(mktemp)
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
mkdir dist
echo $VERSION > .version
echo $NAME > .name
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install
- name: lint
if: runner.os == 'Linux'
run: npm run lint
- run: npm run compile
- name: Build package
if: runner.os == 'Linux'
run: |
npx vsce package -o ${{ steps.set-version.outputs.name }}.vsix
- uses: actions/upload-artifact@v4
if: runner.os == 'Linux'
with:
name: ${{ steps.set-version.outputs.name }}.vsix
path: ${{ steps.set-version.outputs.name }}.vsix
- uses: actions/upload-artifact@v4
if: runner.os == 'Linux'
with:
name: meta
path: |
.name
.version
- uses: actions/checkout@v3
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Find which branch the release tag points at
id: find-branch
if: github.event_name == 'release'
shell: bash
run: |
git fetch --depth=1 origin +refs/heads/*:refs/heads/*
set -x
TAGGEDBRANCH=$(git for-each-ref --points-at=${{github.sha}} --format='%(refname:lstrip=2)' refs/heads/)
echo "taggedbranch=$TAGGEDBRANCH" >> $GITHUB_OUTPUT
- name: Set an output
id: set-version
if: runner.os == 'Linux'
shell: bash
run: |
set -x
VERSION=$(jq -r '.version' package.json | cut -d- -f1)
[ $GITHUB_EVENT_NAME == 'release' ] && VERSION=${{ github.event.release.tag_name }} && VERSION=${VERSION/v/}
CHANGELOG=$(cat CHANGELOG.md | sed -n "/## \[${VERSION}\]/,/## /p" | sed '/^$/d;1d;$d')
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
echo "changelog=$CHANGELOG" >> $GITHUB_OUTPUT
git tag -l | cat
[ $GITHUB_EVENT_NAME == 'push' ] && VERSION+=-beta && VERSION+=.$(($(git tag -l "v$VERSION.*" | sort -nt. -k4 2>/dev/null | tail -1 | cut -d. -f4)+1))
[ $GITHUB_EVENT_NAME == 'pull_request' ] && VERSION+=-dev.${{ github.event.pull_request.number }}
echo "version=$VERSION" >> $GITHUB_OUTPUT
NAME=$(jq -r '.name' package.json)-$VERSION
echo "name=$NAME" >> $GITHUB_OUTPUT
tmp=$(mktemp)
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
mkdir dist
echo $VERSION > .version
echo $NAME > .name
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- run: npm install
- name: lint
if: runner.os == 'Linux'
run: npm run lint
- run: npm run compile
- name: Build package
if: runner.os == 'Linux'
run: |
npx vsce package -o ${{ steps.set-version.outputs.name }}.vsix
- uses: actions/[email protected]
if: (runner.os == 'Linux') && (github.event_name != 'release')
with:
name: ${{ steps.set-version.outputs.name }}.vsix
path: ${{ steps.set-version.outputs.name }}.vsix
beta:
if: (github.event_name == 'push')
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/download-artifact@v4
with:
name: meta
path: .
- name: Set an output
id: set-version
if: runner.os == 'Linux'
run: |
set -x
echo ::set-output name=version::`cat .version`
echo ::set-output name=name::`cat .name`
- uses: actions/download-artifact@v4
with:
name: ${{ steps.set-version.outputs.name }}.vsix
- name: Upload Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v2
if: runner.os == 'Linux'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.set-version.outputs.version }}
prerelease: ${{ github.event_name != 'release' }}
files: ${{ steps.set-version.outputs.name }}.vsix
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/[email protected]
with:
name: ${{ needs.build.outputs.name }}.vsix
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.build.outputs.version }}
name: v${{ needs.build.outputs.version }}
prerelease: ${{ github.event_name != 'release' }}
token: ${{ secrets.GITHUB_TOKEN }}
files: ${{ needs.build.outputs.name }}.vsix
publish:
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release' && needs.build.outputs.taggedbranch == 'master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: master
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
with:
name: meta
path: .
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 14
- name: Prepare build
id: set-version
run: |
VERSION=`cat .version`
NEXT_VERSION=`cat .version | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.`
echo ::set-output name=name::`cat .name`
tmp=$(mktemp)
git config --global user.name 'ProjectBot'
git config --global user.email '[email protected]'
jq --arg version "${NEXT_VERSION}-SNAPSHOT" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
git add package.json
git commit -m 'auto bump version with release'
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
jq '.enableProposedApi = false' package.json > "$tmp" && mv "$tmp" package.json
npm install
git push
- name: Build package
run: |
npx vsce package -o ${{ steps.set-version.outputs.name }}.vsix
- name: Upload Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v2
if: runner.os == 'Linux'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.set-version.outputs.version }}
prerelease: ${{ github.event_name != 'release' }}
files: ${{ steps.set-version.outputs.name }}.vsix
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to VSCode Marketplace
run: |
[ -n "${{ secrets.VSCE_TOKEN }}" ] && \
npx vsce publish --packagePath ${{ steps.set-version.outputs.name }}.vsix -p ${{ secrets.VSCE_TOKEN }} || true
- name: Publish to Open VSX Registry
run: |
[ -n "${{ secrets.OVSX_TOKEN }}" ] && \
npx ovsx publish ${{ steps.set-version.outputs.name }}.vsix --pat ${{ secrets.OVSX_TOKEN }} || true
- uses: actions/checkout@v3
with:
ref: master
token: ${{ secrets.TOKEN }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Prepare build
id: set-version
shell: bash
run: |
VERSION=${{ needs.build.outputs.version }}
NEXT_VERSION=`echo $VERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.`
tmp=$(mktemp)
git config --global user.name 'ProjectBot'
git config --global user.email '[email protected]'
jq --arg version "${NEXT_VERSION}-SNAPSHOT" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
git add package.json
git commit -m 'auto bump version with release [skip ci]'
jq --arg version "$VERSION" '.version = $version' package.json > "$tmp" && mv "$tmp" package.json
jq 'del(.enableProposedApi,.enabledApiProposals)' package.json > "$tmp" && mv "$tmp" package.json
npm install
git push
- name: Build package
run: |
npx vsce package -o ${{ needs.build.outputs.name }}.vsix
- name: Upload Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.release.tag_name }}
files: ${{ needs.build.outputs.name }}.vsix
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to VSCode Marketplace
shell: bash
run: |
[ -n "${{ secrets.VSCE_TOKEN }}" ] && \
npx vsce publish --packagePath ${{ needs.build.outputs.name }}.vsix -p ${{ secrets.VSCE_TOKEN }} || true
- name: Publish to Open VSX Registry
shell: bash
run: |
[ -n "${{ secrets.OVSX_TOKEN }}" ] && \
npx ovsx publish ${{ needs.build.outputs.name }}.vsix --pat ${{ secrets.OVSX_TOKEN }} || true