diff --git a/.github/workflows/release-nightly.yaml b/.github/workflows/release-nightly.yaml index 636d214d..98078ff2 100644 --- a/.github/workflows/release-nightly.yaml +++ b/.github/workflows/release-nightly.yaml @@ -3,24 +3,27 @@ name: Release Nightly on: schedule: - cron: '0 0 * * *' + workflow_call: {} + # Can be triggered manually if needed + workflow_dispatch: {} jobs: - release: + release-nightly: + runs-on: ubuntu-latest + permissions: + contents: write + steps: - uses: actions/checkout@v4 - # TODO if we want to publish this, just a different version is not enough - # We'd probably want to use a different id for the extension, too - e.g. atlascode-nightly - name: Evaluate version run: | - RELEASE_VERSION=$(./nightlyver.sh ${GITHUB_SHA}) && \ - echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV && \ - echo "Using version '${RELEASE_VERSION}'" - - - name: Set version - run: npm -no-git-tag-version --allow-same-version -f version $RELEASE_VERSION + PACKAGE_VERSION=$(./scripts/version/get-next-nightly.sh) + echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV + echo "RELEASE_TAG=v${PACKAGE_VERSION}" >> $GITHUB_ENV + echo "Using version '${PACKAGE_VERSION}'" - name: Set up Node.js uses: actions/setup-node@v4 @@ -28,6 +31,10 @@ jobs: node-version: 20 cache: 'npm' + - name: Set version + run: | + npm -no-git-tag-version --allow-same-version -f version $RELEASE_VERSION + - name: Install dependencies run: npm install @@ -40,4 +47,33 @@ jobs: - name: Build the extension run: npm run extension:package - # No publish actions here for the time being - let's get the builds going first + # No VSCE/OVSX publish actions here for the time being - let's get the builds going first + + - name: Create Tag + run: | + git config --global user.email "atlascode-nightly@atlassian.com" + git config --global user.name "Nightly Release Bot" + git tag -a $RELEASE_TAG -m "Nightly build for $(date +'%Y-%m-%d %H:%M')" + git push origin $RELEASE_TAG + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.RELEASE_TAG }} + release_name: Release ${{ env.RELEASE_TAG }} + draft: false + prerelease: true + + - name: Upload Release Assets + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./atlascode-${{ env.PACKAGE_VERSION }}.vsix + asset_name: atlascode-${{ env.PACKAGE_VERSION }}.vsix + asset_content_type: application/zip diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9efffb08..68f0e7a6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,27 +3,42 @@ name: Release on: push: tags: + - 'v*' + - '!*nightly*' + branches: - '**' jobs: + release-nightly: + uses: ./.github/workflows/release-nightly.yaml + release: runs-on: ubuntu-latest + + # Release the next `nightly` before a stable version + # to prvent folks on pre-releases from being downgraded + needs: release-nightly + + permissions: + contents: write + steps: - uses: actions/checkout@v4 + - name: Evaluate version + run: | + PACKAGE_VERSION=${GITHUB_REF##*/v} + echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_ENV + echo "RELEASE_TAG=v${PACKAGE_VERSION}" >> $GITHUB_ENV + echo "Using version '${PACKAGE_VERSION}'" + - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 20 cache: 'npm' - - name: Evaluate version - run: | - RELEASE_VERSION=${GITHUB_REF##*/v} && \ - echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV && \ - echo "Using version '${RELEASE_VERSION}'" - - name: Set version run: npm -no-git-tag-version --allow-same-version -f version $RELEASE_VERSION @@ -52,12 +67,33 @@ jobs: # echo npx vsce publish \ # -p ${{ secrets.VSCE_MARKETPLACE_TOKEN }} \ # --baseContentUrl https://bitbucket.org/atlassianlabs/atlascode/src/main/ \ - # --packagePath atlascode-${GITHUB_REF##*/v}.vsix + # --packagePath atlascode-${PACKAGE_VERSION}.vsix - name: Publish to OpenVSX run: | npx ovsx verify-pat -p ${{ secrets.OPENVSX_KEY }} # echo npx ovsx publish \ # -p ${{ secrets.OPENVSX_KEY }} \ - # "atlascode-${GITHUB_REF##*/v}.vsix" + # "atlascode-${PACKAGE_VERSION}.vsix" + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.RELEASE_TAG }} + release_name: Release ${{ env.RELEASE_TAG }} + draft: false + prerelease: false + + - name: Upload Release Assets + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./atlascode-${{ env.PACKAGE_VERSION }}.vsix + asset_name: atlascode-${{ env.PACKAGE_VERSION }}.vsix + asset_content_type: application/zip diff --git a/scripts/version/get-latest-nightly.sh b/scripts/version/get-latest-nightly.sh new file mode 100755 index 00000000..00a2eb11 --- /dev/null +++ b/scripts/version/get-latest-nightly.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +n_release=${1:-1} + +# Get latest nightly tag from the repository +# Pre-releases are defined by the version number having an ODD minor number +# https://code.visualstudio.com/api/working-with-extensions/publishing-extension#prerelease-extensions +git tag --list | \ + sort --version-sort -r | \ + grep -E '^v[0-9]+\.[0-9]*[13579]\.[0-9]+.*' | \ + head -n $n_release | \ + tail -n 1 | \ + cut -c 2- diff --git a/scripts/version/get-latest-stable.sh b/scripts/version/get-latest-stable.sh new file mode 100755 index 00000000..7b895d7a --- /dev/null +++ b/scripts/version/get-latest-stable.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +n_release=${1:-1} + +# Get latest release tag from the repository +# Stable releases are defined by the version number having an EVEN minor number +# https://code.visualstudio.com/api/working-with-extensions/publishing-extension#prerelease-extensions +git tag --list | \ + sort --version-sort -r | \ + grep -E '^v[0-9]+\.[0-9]*[02468]\.[0-9]+$' | \ + head -n $n_release | \ + tail -n 1 | \ + cut -c 2- diff --git a/scripts/version/get-next-nightly.sh b/scripts/version/get-next-nightly.sh new file mode 100755 index 00000000..75a123c3 --- /dev/null +++ b/scripts/version/get-next-nightly.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Nightly version is defined by the latest stable release tag, +# except the minor version is incremented by one +# https://code.visualstudio.com/api/working-with-extensions/publishing-extension#prerelease-extensions + +git fetch --tags -q +latest_stable_version=$(./scripts/version/get-latest-stable.sh) +latest_nightly_version=$(./scripts/version/get-latest-nightly.sh) + +# Major version is the same as the latest stable version +stable_major=$(echo $latest_stable_version | cut -d '.' -f 1) +nightly_major=$(echo $latest_nightly_version | cut -d '.' -f 1) + +# Minor version is always "latest stable + 1" +stable_minor=$(echo $latest_stable_version | cut -d '.' -f 2) +nightly_minor=$(echo $latest_nightly_version | cut -d '.' -f 2) +next_minor=$((stable_minor + 1)) + +# Patch is incrementing, unless we're on a new minor +if [[ $nightly_major -eq $stable_major && $next_minor -eq $nightly_minor ]]; then + nightly_patch=$(echo $latest_nightly_version | cut -d '.' -f 3 | cut -d '-' -f 1) + nightly_patch=${nightly_patch:--1} # In case of new nightly minor + next_patch=$((nightly_patch + 1)) +else + next_patch=0 +fi + +echo "$stable_major.$next_minor.$next_patch-nightly"