1

Github Actions workflow for a private repository:

Within IntelliJ project OrionDAO is a facet of project Orion and so has to be run first.

Part of OrionDAO Pom follows:

<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>uk.co.xxxx.orionDAO</groupId>
   <artifactId>orionDAO</artifactId>
   <packaging>jar</packaging>
   <name>Orion Model</name>
   <description>Orion </description>
   <version>25.1.3</version>

……….


   <distributionManagement>
      <repository>
         <id>github</id>
         <name>Apache Maven Packages</name>
         <url>https://maven.pkg.github.com/xxxx/Orion_CICD</url>
      </repository>
   </distributionManagement>
</project>

Part of Orion Pom follows:

4.0.0

<groupId>uk.co.xxxx.orion</groupId>
<artifactId>orion</artifactId>
<version>25.1.3</version>
<packaging>war</packaging>

<name>Orion</name>
<description>Orion </description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>15</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <hapi-fhir-version>4.2.0</hapi-fhir-version>

</properties>

<dependencies>
    <dependency>
        <groupId>uk.co.xxxx.orionDAO</groupId>
        <artifactId>orionDAO</artifactId>
        <version>25.1.3</version>
        <scope>provided</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
    </plugins>
    <finalName>orion</finalName>
</build>

<distributionManagement>
    <repository>
        <id>github</id>
        <name>GitHub ReedInPartnership Apache Maven Packages</name>
        <url>https://maven.pkg.github.com/xxxx/Orion_CICD</url>
    </repository>
</distributionManagement>

This all works fine until the deploy step.

Then it just sits there.

I added permissions: step but still hangs.

# This workflow will trigger when a PR is closed and will put out a message
# dependant upon Orion being built and deployed to the Master branch

name: Master Workflow - PR message output and build and deploy
on:
  pull_request:
    types: closed
    branches:
      - master

permissions:
  contents: read
  packages: write

jobs:
  merge_job:
    # this job will only run if the PR has been merged
    if: github.event.pull_request.merged == true
    runs-on: windows-latest
    steps:
      - run: |
          echo PR #${{ github.event.number }} has been merged

  close_job:
    # this job will only run if the PR has been closed without being merged
    if: github.event.pull_request.merged == false
    runs-on: windows-latest
    steps:
      - run: |
          echo PR #${{ github.event.number }} has been closed without being merged

  deploy_job:
    # this job will only run if the PR has been merged i.e merge-job completed successfully
    needs: merge_job
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 16 for now
        uses: actions/setup-java@v2
        with:
          java-version: '16'
          distribution: 'adopt'

      - name: Set up Maven
        uses: stCarolas/setup-maven@v4
        with:
          maven-version: 3.6.3

      - name: Cache Maven packages
        uses: actions/cache@v2
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2

      - name: 'Create settings.xml'
        uses: whelk-io/maven-settings-xml-action@v4
        with:
          repositories: '[{ "id": "github", "url": "https://maven.pkg.github.com/ReedInPartnership/Orion_CICD" }]'
          servers: '[{"id": "github", "username": "${{ secrets.GITHUB_USERNAME }}", "password": "${{ secrets.GITHUB_PASSWORD }}"}]'

      - name: Install Jespa
        run: mvn install:install-file "-Dfile=Orion\jespa-1.2.6.jar" "-DgroupId=jespa" "-DartifactId=jespa" "-Dversion=1.2.6" "-Dpackaging=jar" "-DgeneratePom=true"

      - name: Build with Maven (Orion DAO)
        run: mvn -B install --file Orion_DAO/pom.xml

      - name: Build with Maven (Orion)
        run: mvn -B install --file Orion/pom.xml

      - name: Publish to GitHub Packages Orion
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: mvn --batch-mode --file Orion/pom.xml deploy

Output: Just hangs when uploading jar and pom to github Maven Deploy

Hanging on install

***** UPDATE ***** ***** UPDATE ***** ***** UPDATE *****

This was done with myself as the creator of the merge request and also as the the person merging it and I thought maybe this is why it is hanging. So I got someone else (the reviewer) to do the merge and now it is not hanging but I am getting the following error instead

Error:  Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project orion: Failed to deploy artifacts: Could not transfer artifact uk.co.reed.orion:orion:war:25.1.3 from/to github (https://maven.pkg.github.com/xxxx/Orion_CICD): Transfer failed for https://maven.pkg.github.com/xxxx/Orion_CICD/uk/co/reed/orion/orion/25.1.3/orion-25.1.3.war 401 Unauthorized -> [Help 1]
Error:  
Error:  To see the full stack trace of the errors, re-run Maven with the -e switch.
Error:  Re-run Maven using the -X switch to enable full debug logging.
Error:  
Error:  For more information about the errors and possible solutions, please read the following articles:
Error:  [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Error: Process completed with exit code 1.

***** UPDATE2 ***** ***** UPDATE2 ***** ***** UPDATE2 *****

I have now gotten another reviewer with admin access to merge this and we are back to the workflow just hanging in the maven deploy step!!

charlie f
  • 231
  • 1
  • 2
  • 13

2 Answers2

0

In the end I created a release workflow and then it created the packages. It seems that packages are only created on a release event type although I couldn't find this mentioned in all the documentation I read.

# This workflow will build and publish to Github Packages on release

name: Master Workflow - Build and Publish to GitHub Packages
on:
  release:
    types: [created]
jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v2
        with:
          java-version: '16'
          distribution: 'adopt'

      - name: Install Jespa
        run: mvn install:install-file "-Dfile=Orion\jespa-1.2.6.jar" "-DgroupId=jespa" "-DartifactId=jespa" "-Dversion=1.2.6" "-Dpackaging=jar" "-DgeneratePom=true"

      - name: Build with Maven (Orion DAO)
        run: mvn -B install --file Orion_DAO/pom.xml

      - name: Build with Maven (Orion)
        run: mvn -B install --file Orion/pom.xml

      - name: Publish package
        run: mvn --batch-mode --file Orion/pom.xml deploy
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
charlie f
  • 231
  • 1
  • 2
  • 13
0

You can add settings.xml to the project root folder same location as pom.xml

Then you can add steps like this:

- name: Build with Maven
   env:
      USENAME: ${{github.actor}}
      PASSWORD: ${{ secrets.GITHUB_TOKEN }}
   run: mvn -B clean package --settings settings.xml

Content of the settings.xml :

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

    <servers>
        <server>
            <id>github</id>
            <username>${env.USERNAME}</username>
            <password>${env.PASSWORD}</password>
        </server>

    </servers>

</settings>
sendon1982
  • 9,982
  • 61
  • 44