halo.yml 4.7 KB
Newer Older
1 2 3 4 5
name: Halo CI

on:
  pull_request:
    paths:
6 7
      - "**"
      - "!**.md"
8 9
  push:
    branches:
10
      - "**"
11
    paths:
12 13
      - "**"
      - "!**.md"
14 15 16 17 18 19 20 21 22 23 24 25 26
  release:
    types: # This configuration does not affect the page_build event above
      - created

jobs:
  check:
    runs-on: ubuntu-latest
    # Default steps
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Set up JDK 11
27
        uses: actions/setup-java@v2
28
        with:
29 30
          distribution: 'temurin'
          cache: 'gradle'
31 32 33 34 35 36 37 38 39 40 41 42 43
          java-version: 11
      - name: Check And Test
        run: ./gradlew check
  build:
    runs-on: ubuntu-latest
    needs: check
    if: github.event_name == 'release'
    # Default steps
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Set up JDK 11
44
        uses: actions/setup-java@v2
45
        with:
46 47
          distribution: 'temurin'
          cache: 'gradle'
48 49
          java-version: 11
      - name: Build with Gradle
50 51
        run: |
          # Set the version with tag name when releasing
52 53 54
          version=${{ github.event.release.tag_name }}
          version=${version#v}
          sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties
55
          ./gradlew clean build -x test
56 57 58 59
      - name: Archive halo jar
        uses: actions/upload-artifact@v2
        with:
          name: halo-jar
RYAN0UP's avatar
RYAN0UP 已提交
60 61 62
          path: |
            build/libs
            !build/libs/*-plain.jar
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
          retention-days: 1
  github-release:
    runs-on: ubuntu-latest
    needs: build
    if: github.event_name == 'release'
    steps:
      - name: Download halo jar
        uses: actions/download-artifact@v2
        with:
          name: halo-jar
          path: build/libs
      - name: Get Name of Artifact
        id: get_artifact
        run: |
          ARTIFACT_PATHNAME=$(ls build/libs/*.jar | head -n 1)
          ARTIFACT_NAME=$(basename ${ARTIFACT_PATHNAME})
          echo "Artifact pathname: ${ARTIFACT_PATHNAME}"
          echo "Artifact name: ${ARTIFACT_NAME}"
          echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV
          echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
          echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV
      - name: Upload a Release Asset
        uses: actions/github-script@v2
        if: github.event_name == 'release'
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            console.log('environment', process.versions);

            const fs = require('fs').promises;

            const { repo: { owner, repo }, sha } = context;
            console.log({ owner, repo, sha });

            const releaseId = process.env.RELEASE_ID
            const artifactPathName = process.env.ARTIFACT_PATHNAME
            const artifactName = process.env.ARTIFACT_NAME
            console.log('Releasing', releaseId, artifactPathName, artifactName)

            await github.repos.uploadReleaseAsset({
              owner, repo,
              release_id: releaseId,
              name: artifactName,
              data: await fs.readFile(artifactPathName)
            });
  docker-release:
    runs-on: ubuntu-latest
    needs: build
    if: github.event_name == 'release'
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
116 117
      - name: Download halo jar
        uses: actions/download-artifact@v2
118
        with:
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
          name: halo-jar
          path: build/libs
      - name: Docker meta for Halo
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: |
            halohub/halo
            ghcr.io/${{ github.repository_owner }}/halo
          tags: |
            type=schedule
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{ version }}
            type=semver,pattern={{major}}.{{minor}}
            type=sha
135 136 137 138
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
139
      - name: Login to DockerHub
140 141 142 143
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}
144 145
      - name: Login to GHCR
        uses: docker/login-action@v1
146
        with:
147 148 149 150
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GHCR_TOKEN }}
      - name: Build and push
151 152 153 154
        uses: docker/build-push-action@v2
        with:
          context: .
          file: ./Dockerfile
155 156 157
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          labels: ${{ steps.meta.outputs.labels }}
          tags: ${{ steps.meta.outputs.tags }}
158
          push: true