Skip to content

Commit

Permalink
Add github action to release packages (#78)
Browse files Browse the repository at this point in the history
* Add github release action.

* add workflow_dispatch trigger

* Fix publish configuration.

* Also add release option.

* Fix linux publish command.

* Fix action file.

* Fix action file.

* Fix gradle properties.

* Allow package write.

* Do not create GH release

* Add release option.
  • Loading branch information
aoli-al authored Dec 22, 2024
1 parent 51f16b8 commit 6edd0cc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 21 deletions.
79 changes: 70 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,85 @@
name: Publish package to GitHub Packages
on:
release:
types: [created]
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
inputs:
mode:
description: 'staging/snapshot, default is snapshot'
required: true
default: 'snapshot'


jobs:
publish:
check_date:
runs-on: ubuntu-latest
name: Check latest commit
outputs:
should_run: ${{ steps.should_run.outputs.should_run }}
steps:
- uses: actions/checkout@v2
- name: print latest_commit
run: echo ${{ github.sha }}

- id: should_run
continue-on-error: true
name: check latest commit is less than a day
if: ${{ github.event_name == 'schedule' }}
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false"
publish:
needs: check_date
if: github.repository == 'cmu-pasta/fray' && needs.check_date.outputs.should_run != 'false'
runs-on: ${{ matrix.operating-system }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
operating-system: [ macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
distribution: 'corretto'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda # v3.4.2

- name: Publish package
run: ./gradlew publish
cache: 'gradle'
- uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('*/build.gradle.kts', 'engines/**/build.gradle.kts', 'extensions/**/build.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Read and update version
run: |
BASE_VERSION=$(grep "^version=" gradle.properties | cut -d'=' -f2)
if [[ "${{ github.event.inputs.mode }}" == "staging" ]]; then
BASE_VERSION=${BASE_VERSION/-SNAPSHOT/}
fi
echo "VERSION=${BASE_VERSION}" >> $GITHUB_ENV
echo "Version: $BASE_VERSION"
- name: build the repository
run: ./gradlew build
- name: publish to github package repository (macOS)
if: runner.os == 'macOS'
run: ./gradlew :jvmti:publish -Pversion=$VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: publish to github package repository (Linux)
if: runner.os == 'Linux'
run: ./gradlew publish -Pversion=$VERSION
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/create-release@v1
if: runner.os == 'Linux'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: "Release ${{ env.VERSION }}"
body: |
This release includes the following:
- Version: `${{ env.VERSION }}`
- Published packages are available in [GitHub Packages](https://github.com/orgs/cmu-pasta/packages?repo_name=fray).
draft: false
prerelease: true
14 changes: 2 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import groovy.namespace.QName
import groovy.util.Node
import groovy.util.NodeList
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import java.util.regex.Pattern

plugins {
kotlin("jvm") version "2.0.0"
Expand All @@ -11,12 +7,6 @@ plugins {
id("org.jetbrains.dokka") version "1.9.20"
}


allprojects {
group = "org.pastalab.fray"
version = "0.1.6-SNAPSHOT"
}

repositories {
mavenCentral()
}
Expand Down Expand Up @@ -77,8 +67,8 @@ configure(allprojects - rootProject - project(":instrumentation")) {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/cmu-pasta/fray")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
kotlin.code.style=official
group=org.pastalab.fray
version=0.1.6-SNAPSHOT

0 comments on commit 6edd0cc

Please sign in to comment.