Skip to content

Commit

Permalink
chore(archetype): add GitHub workflows and update .mvn
Browse files Browse the repository at this point in the history
  • Loading branch information
xooooooooox committed Jan 1, 2025
1 parent 5a52e55 commit da78aee
Show file tree
Hide file tree
Showing 31 changed files with 2,111 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [x] Support publish GitLab pages via GitLab CI/CD
- [x] Optimize gitlab ci pipeline, use remote template
- [x] Update archetype, .mvn, .github actions

## 0.6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,20 @@
<include>.tool-versions</include>
</includes>
</fileSet>
<!-- github -->
<fileSet encoding="UTF-8">
<directory>.github</directory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<!-- mvn -->
<fileSet encoding="UTF-8">
<directory>.mvn</directory>
<includes>
<include>**/*.config</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# todo: git push 由于 credentials and gitconfig 问题, 暂时搁置该 workflow
name: "[Tags] Create tag"

on:
workflow_dispatch:

jobs:
prepare_tag:
# Only proceed if the workflow dispatch event is for the "main" branch
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
passphrase: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}

- name: Configure GPG for CI
run: |
mkdir -p ~/.gnupg
chmod 700 ~/.gnupg
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
- name: Test GPG signing
run: |
gpg -K
echo "test gpg" > test.txt
gpg -ab test.txt
gpg --verify test.txt.asc
rm test.txt test.txt.asc
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
server-id: central-portal
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD

# resolve miss user.name and user.email gitconfig when push
- name: Set up Git config
run: |
git config --global user.name "${{ secrets.GH_USER_NAME }}"
git config --global user.email "${{ secrets.GH_USER_EMAIL }}"
- name: Prepare release tag
run: |
./mvnw clean -Pcoding,auto-release release:prepare -B --settings .mvn/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: "[Release] Publish releases packages to Maven Central"

on:
release:
types: [ created ] # triggers on release creation

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Validate tag version format
run: |
# Fail if the release tag doesn't match x.x or x.x.x
if [[ ! "${{ github.event.release.tag_name }}" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
echo "::error ::Invalid version format '${{ github.event.release.tag_name }}'. Must match x.x or x.x.x."
exit 1
fi
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
passphrase: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}

- name: Configure GPG for CI
run: |
mkdir -p ~/.gnupg
chmod 700 ~/.gnupg
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
- name: Test GPG signing
run: |
gpg -K
echo "test gpg" > test.txt
gpg -ab test.txt
gpg --verify test.txt.asc
rm test.txt test.txt.asc
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
server-id: central-portal
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD

- name: Set version
run: |
./mvnw versions:set -DnewVersion=${{ github.event.release.tag_name }}
- name: Publish package
run: |
./mvnw --batch-mode clean deploy \
-Pcoding,publish-central -DskipTests --settings .mvn/settings.xml
env:
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
GPG_KEYID: ${{ secrets.GPG_KEYID }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "[Snapshots] Publish snapshots package to GitHub Packages"

on:
push:
branches:
- main
paths-ignore:
- '.github/**'
- '.gitlab/**'
- 'Writerside/**'
- '.mvn/**'
- '**/*.md'
- '*.yml'
workflow_dispatch:

jobs:
publish:
# 当在 main 分支执行 ./mvnw release:prepare 时, 会产生两次 push 到 main, 避免触发重复 ci/cd(两次)
# skip if commit message has [maven-release-plugin] prepare release
if: "! contains(github.event.head_commit.message, '[maven-release-plugin] prepare release')"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_SIGNING_KEY }}
passphrase: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}

- name: Configure GPG for CI
run: |
mkdir -p ~/.gnupg
chmod 700 ~/.gnupg
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
- name: Test GPG signing
run: |
gpg -K
echo "test gpg" > test.txt
gpg -ab test.txt
gpg --verify test.txt.asc
rm test.txt test.txt.asc
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Publish to GitHub Packages
run: |
./mvnw --batch-mode clean deploy \
-Pcoding,publish-github -DskipTests --settings .mvn/settings.xml
env:
GITHUB_USERNAME: ${{ secrets.GH_USERNAME}}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# see https://www.jetbrains.com/help/writerside/deploy-docs-to-github-pages.html
name: "[Pages] Trigger Build Writerside documentation"

on:
push:
branches:
- main
- feat/241230-0.7
paths: [ 'Writerside/*' ]
workflow_dispatch:

permissions:
contents: read
id-token: write
pages: write

env:
INSTANCE: 'Writerside/radp'
DOCKER_VERSION: '243.22562'

jobs:
build:
runs-on: ubuntu-latest
outputs:
algolia_artifact: ${{ steps.define-ids.outputs.algolia_artifact }}
artifact: ${{ steps.define-ids.outputs.artifact }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Define instance id and artifacts
id: define-ids
run: |
INSTANCE=${INSTANCE#*/}
INSTANCE_ID_UPPER=$(echo "$INSTANCE" | tr '[:lower:]' '[:upper:]')
ARTIFACT="webHelp${INSTANCE_ID_UPPER}2-all.zip"
ALGOLIA_ARTIFACT="algolia-indexes-${INSTANCE_ID_UPPER}.zip"
# Print the values
echo "INSTANCE_ID_UPPER: $INSTANCE_ID_UPPER"
echo "ARTIFACT: $ARTIFACT"
echo "ALGOLIA_ARTIFACT: $ALGOLIA_ARTIFACT"
# Set the environment variables and outputs
echo "INSTANCE_ID_UPPER=$INSTANCE_ID_UPPER" >> $GITHUB_ENV
echo "ARTIFACT=$ARTIFACT" >> $GITHUB_ENV
echo "ALGOLIA_ARTIFACT=$ALGOLIA_ARTIFACT" >> $GITHUB_ENV
echo "artifact=$ARTIFACT" >> $GITHUB_OUTPUT
echo "algolia_artifact=$ALGOLIA_ARTIFACT" >> $GITHUB_OUTPUT
- name: Build docs using Writerside Docker builder
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}

- name: Save artifact with build results
uses: actions/upload-artifact@v4
with:
name: docs
path: |
artifacts/${{ env.ARTIFACT }}
artifacts/report.json
artifacts/${{ env.ALGOLIA_ARTIFACT }}
retention-days: 7
test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docs
path: artifacts

- name: Test documentation
uses: JetBrains/writerside-checker-action@v1
with:
instance: ${{ env.INSTANCE }}
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docs
path: artifacts

- name: Unzip artifact
run: unzip -O UTF-8 -qq "artifacts/${{ needs.build.outputs.artifact }}" -d dir

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Package and upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: dir

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Loading

0 comments on commit da78aee

Please sign in to comment.