Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI action #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add CI action #30

wants to merge 1 commit into from

Conversation

foxdalas
Copy link

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
Copy link
Owner

a-langer commented Aug 4, 2024

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
Copy link
Author

foxdalas commented Aug 12, 2024

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants