Skip to content

Commit

Permalink
chore: Migrate release/build to Github Actions (#641)
Browse files Browse the repository at this point in the history
* chore: Migrate release/build to Github Actions

Signed-off-by: Stephane Bouchet <[email protected]>

* chore: Migrate release/build to Github Actions

Signed-off-by: Stephane Bouchet <[email protected]>

* added gradle wrapper validation before build

Signed-off-by: Stephane Bouchet <[email protected]>

---------

Signed-off-by: Stephane Bouchet <[email protected]>
  • Loading branch information
sbouchet authored Dec 13, 2023
1 parent e1d81c7 commit 6f7dc66
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 31 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Nightly Build
on:
schedule:
- cron: '0 1 * * *'
workflow_dispatch:
inputs:
publishToMarketPlace:
description: 'Publish to JetBrains Marketplace ?'
required: true
type: choice
options:
- 'true'
- 'false'
default: 'false'

jobs:
should-build-change:
runs-on: ubuntu-latest
outputs:
repo-cache-hit: ${{ steps.cache-last-commit.outputs.cache-hit }}
steps:
- name: Fetch Sources
uses: actions/checkout@v4
- name: validate Gradle Wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 #v1.1.0
- run: |
git rev-parse HEAD >> lastCommit
- name: Check New Changes
id: cache-last-commit
uses: actions/cache@v3
with:
path: lastCommit
key: lastCommit-${{ hashFiles('lastCommit') }}

# Prepare and publish the plugin to JetBrains Marketplace repository
pre-release:
needs: should-build-change
if: ${{ needs.should-build-change.outputs.repo-cache-hit != 'true' || github.event_name != 'schedule' }}
name: Publish Plugin
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# Check out current repository
- name: Fetch Sources
uses: actions/checkout@v4

# Set up Java environment for the next steps
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17

# Setup Gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true

- name: Publish Plugin
env:
PUBLISH_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}
run: |
CURRENT_VERSION=$(grep "projectVersion=" gradle.properties | cut -d'=' -f2)
BASE_VERSION=${CURRENT_VERSION%-SNAPSHOT}
TIMESTAMP=$(date +'%Y%m%d-%H%M%S')
PLUGIN_VERSION="${BASE_VERSION}-$TIMESTAMP"
./gradlew publishPlugin -PprojectVersion=${PLUGIN_VERSION} -Pchannel=nightly -PpluginVersion=${PLUGIN_VERSION}
133 changes: 102 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,119 @@
name: Generate changelog and plugin archive for new release
name: Release Plugin

#Only one job at a time
concurrency: release

on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
publishToMarketPlace:
description: 'Publish to JetBrains Marketplace ?'
required: true
type: choice
options:
- 'true'
- 'false'
default: 'false'

jobs:
build:
# Prepare and publish the plugin to JetBrains Marketplace repository
release:
if: ${{ inputs.publishToMarketPlace == 'true'}}
name: Publish to Marketplace
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
# Check out current repository
- name: Fetch Sources
uses: actions/checkout@v4

# Validate Wrapper before running build
- name: validate Gradle Wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 #v1.1.0

# Set up Java environment for the next steps
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
distribution: 'temurin'
cache: 'gradle'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew buildPlugin
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

# Setup Gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true

- name: Set Release Version
id: release_version
shell: bash
run: |
CURRENT_VERSION=$(grep "projectVersion=" gradle.properties | cut -d'=' -f2)
NEW_VERSION=${CURRENT_VERSION%-SNAPSHOT}
awk -v current="$CURRENT_VERSION" -v new="$NEW_VERSION" 'BEGIN {FS=OFS="="} $1 == "projectVersion" { $2 = new }1' gradle.properties > tmpfile && mv tmpfile gradle.properties
echo "Release version: $NEW_VERSION"
echo "PLUGIN_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
# Publish the plugin to JetBrains Marketplace
- name: Publish Plugin to JetBrains Marketplace
env:
PUBLISH_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}
run: |
./gradlew publishPlugin -PprojectVersion=$PLUGIN_VERSION -Pchannel=stable -PjetBrainsToken=$PUBLISH_TOKEN
echo "Published $PLUGIN_VERSION to the Jetbrains Marketplace"
- name: Tag Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "[email protected]"
git config user.name "GitHub Action"
if git diff --quiet; then
echo "No changes to commit."
else
git commit -sam "chore(skip-release): set version to $PLUGIN_VERSION"
fi
git tag $PLUGIN_VERSION
git push origin $PLUGIN_VERSION
# Set next SNAPSHOT version
- name: Increment Plugin Version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CURRENT_VERSION=$(grep "projectVersion=" gradle.properties | cut -d'=' -f2)
IFS="-" read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
IFS="." read -ra VERSION_NUM <<< "${VERSION_PARTS[0]}"
((VERSION_NUM[2]++))
NEW_VERSION="${VERSION_NUM[0]}.${VERSION_NUM[1]}.${VERSION_NUM[2]}-SNAPSHOT"
awk -v new_version="$NEW_VERSION" '/projectVersion=/{sub(/=.*/, "=" new_version)}1' gradle.properties > tmpfile && mv tmpfile gradle.properties
echo "Set $NEW_VERSION in gradle.properties"
git commit -sam "chore(skip-release): set version to $NEW_VERSION"
git push origin main
- name: Simple conventional changelog
uses: lstocchi/simple-conventional-changelog@13071c09073f5deddf03d44d9af6a8b0f81ef227 #0.0.11
id: changelog
with:
token: ${{ secrets.GITHUB_TOKEN }}
current-tag: ${{ steps.get_version.outputs.VERSION }}
current-tag: ${{env.PLUGIN_VERSION}}
types-mapping: 'feat:Features,fix:Bug Fixes,docs:Documentation,refactor:Refactoring,build:Builds,chore:Other'
- name: Create Release
id: create_release
uses: actions/create-release@v1

# Create a new Github release
- name: Create Github Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: ${{ steps.get_version.outputs.VERSION }}
body: ${{ steps.changelog.outputs.changelog }}
- name: Attach zip to release
uses: actions/upload-release-asset@v1
run: |
gh release create ${PLUGIN_VERSION} \
--title "${PLUGIN_VERSION}" \
--notes "$(cat << 'EOM'
${{ steps.changelog.outputs.changelog }}
EOM
)"
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: '${{ github.workspace }}/build/distributions/org.jboss.tools.intellij.openshift-${{ steps.get_version.outputs.VERSION }}.zip'
asset_name: 'OpenShift Toolkit-${{ steps.get_version.outputs.VERSION }}.zip'
asset_content_type: application/zip
run: gh release upload ${PLUGIN_VERSION} ./build/distributions/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ target
build
.gradle
out
bin/

lsp/
/.run/

0 comments on commit 6f7dc66

Please sign in to comment.