|
| 1 | +name: Package and Release JAR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + jar-and-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Inject version into fabric.mod.json |
| 21 | + run: | |
| 22 | + set -euo pipefail |
| 23 | + SHORT_SHA="${GITHUB_SHA:0:7}" |
| 24 | + VERSION="v-$(date -u +%Y%m%d%H%M%S)-${SHORT_SHA}" |
| 25 | +
|
| 26 | + jq --arg v "$VERSION" '.version = $v' fabric.mod.json > fabric.mod.json.tmp |
| 27 | + mv fabric.mod.json.tmp fabric.mod.json |
| 28 | +
|
| 29 | + echo "INJECTED_VERSION=$VERSION" >> $GITHUB_ENV |
| 30 | +
|
| 31 | + - name: Create JAR of repository |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | +
|
| 35 | + SHORT_SHA="${GITHUB_SHA:0:7}" |
| 36 | + JAR_NAME="repo-${SHORT_SHA}.jar" |
| 37 | +
|
| 38 | + find . -type f \ |
| 39 | + ! -path "./.git/*" \ |
| 40 | + ! -name "$JAR_NAME" \ |
| 41 | + -print | sed 's|^\./||' > filelist.txt |
| 42 | +
|
| 43 | + jar cf "$JAR_NAME" -C . -@ < filelist.txt |
| 44 | +
|
| 45 | + echo "ZIP_NAME=$JAR_NAME" >> $GITHUB_ENV |
| 46 | +
|
| 47 | + - name: Create GitHub release and attach JAR |
| 48 | + env: |
| 49 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + ZIP_NAME: ${{ env.ZIP_NAME }} |
| 51 | + run: | |
| 52 | + set -euo pipefail |
| 53 | +
|
| 54 | + SHORT_SHA="${GITHUB_SHA:0:7}" |
| 55 | + TAG="v-$(date -u +%Y%m%d%H%M%S)-${SHORT_SHA}" |
| 56 | + TITLE="Automated release ${TAG}" |
| 57 | + NOTES="Automated release for commit ${GITHUB_SHA} on branch ${GITHUB_REF#refs/heads/}" |
| 58 | +
|
| 59 | + gh release create "$TAG" "$ZIP_NAME" \ |
| 60 | + -t "$TITLE" \ |
| 61 | + -n "$NOTES" \ |
| 62 | + --repo "${{ github.repository }}" |
| 63 | +
|
| 64 | + echo "Created release $TAG with asset $ZIP_NAME" |
0 commit comments