a-langer / nexus-sso

Single Sign-On patch for Nexus OSS
Eclipse Public License 1.0
67 stars 16 forks source link

Add CI action #30

Open foxdalas opened 1 month ago

foxdalas commented 1 month ago

Hi @a-langer,

I've added a GitHub Action to your project. You can see an example release here.

Why this change? It allows everyone to easily obtain JAR files from your project and use them in their own projects and Docker files.

a-langer commented 1 month ago

Hi @foxdalas,

Thanks for the work done. I have a few questions:

  1. Am I right in understanding that a release is created only when pushing with a tag?
  2. Will a release be created when a merge request is accepted?
  3. What happens if the tag is added to a side branch (not main)?
foxdalas commented 1 month ago

Hi @foxdalas,

Thanks for the work done. I have a few questions:

  1. Am I right in understanding that a release is created only when pushing with a tag?

Yes, you are right

  1. Will a release be created when a merge request is accepted?

No, a release is only created for new tags. (see push section)

  1. What happens if the tag is added to a side branch (not main)? It will still trigger a release.

I can add a tag pattern and specify the branch, as you wish.

a-langer commented 1 month ago

I think that releases should be issued only on the "main" branch with a tag. If I'm not mistaken, the condition will be as follows:

if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'

As far as I understand, this condition should also be added to the "Checkout" and "Run the Maven verify phase" jobs.

Ideally, it would be good to also release a Docker image. I looked at one of the forks, where the Docker image release is implemented https://github.com/brbcza/nexus-sso/blob/main/.github/workflows/deploy_release.yml, I think we can use this build script as a base to get something like this:

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

      # Enable multi-architecture support on build node
      - name: Set up QEMU
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        uses: docker/setup-qemu-action@v3
        with:
          platforms: all

      - name: Set up Docker buildx
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        uses: docker/setup-buildx-action@v3
        with:
          version: latest

      - name: Set up JDK 11 for x64
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        uses: actions/setup-java@v4
        with:
          java-version: '11'
          distribution: 'temurin'
          architecture: x64
          cache: 'maven'

      - name: Run the Maven verify phase
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        run: mvn --batch-mode --update-snapshots verify

      - name: Login to GitHub container registry
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build Docker image with Maven
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        run: |
          mvn install -PprepareImage

      - name: Build and push Docker image
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        uses: docker/build-push-action@v5
        with:
            context: .
            push: true
            build-args: |
              NEXUS_VERSION=$GITHUB_REF_NAME
            tags: |
              ghcr.io/${{ github.repository }}:$GITHUB_REF_NAME
            platforms: linux/amd64,linux/arm64,linux/arm/v7
            cache-from: type=gha
            cache-to: type=gha,mode=max

      - name: Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main'
        with:
          files: |
            LICENSE
            nexus-pac4j-plugin/target/*.jar
            nexus-repository-services/target/*.jar

Of course I haven't tested this and most likely made a lot of mistakes.