1
votes

I am using GitHub Actions for Gradle project with this given steps:

name: Java CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - run: gradle wrapper

      - run: ./gradlew bootJar

      - run: ls ./build/libs/

      - uses: actions/checkout@v1
      - name: Login to docker
        run: docker login docker.pkg.github.com -u xxxxxx -p xxxxxx

      - uses: actions/checkout@v1
      - name: Build the Docker image
        run: docker build . -t realtimechat-snapshot-0.$GITHUB_REF


      - uses: actions/checkout@v1
      - name: Tag the image
        run: docker tag realtimechat-snapshot-0.$GITHUB_REF realtimechat-snapshot-0



      - uses: actions/checkout@v1
      - name: Push the image
        run: docker push realtimechat-snapshot-0.$GITHUB_REF


at Build the Docker image step it build this Dockerfile:

FROM alpine:latest
COPY ./build/libs/realtimeChattingSystem-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar

and when it tries to copy the jar file I get this error:

COPY failed: stat /var/lib/docker/tmp/docker-builder207778036/build/libs/realtimeChattingSystem-0.0.1-SNAPSHOT.jar: no such file or directory

NOTE*

at - run: ls ./build/libs/ in the steps it actually shows me the jar file:

Run ls ./build/libs/

realtimeChattingSystem-0.0.1-SNAPSHOT.jar

Issue #2

after doing the changes in this post

I faced another issue

this is the steps:

name: Java CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Set up JDK 13
        uses: actions/setup-java@v1
        with:
          java-version: 13

      - run: ./gradlew bootJar

      - name: Login to Github regestry
        run: docker login docker.pkg.github.com -u xxxxx -p xxxxx

      - name: Build the Docker image
        run: docker build . -t docker.pkg.github.com/sulimanlab/realtime-chat/realtimechat-snapshot-0.$GITHUB_REF


      - name: Push the image to github
        run: docker push docker.pkg.github.com/sulimanlab/realtime-chat/realtimechat-snapshot-0.$GITHUB_REF


At the last step I get this error:

The push refers to repository [docker.pkg.github.com/sulimanlab/realtime-chat/realtimechat-snapshot-0.refs/heads/master]

3aad04996f8f: Preparing

77cae8ab23bf: Preparing

error parsing HTTP 404 response body: invalid character 'p' after top-level value: "404 page not found\n"

1
Why are you checking out your repo over and over again? Note there is an issue with using that action more than once. If you need access to the root folder where your repo lives, try using the environment variable GITHUB_WORKSPACE, but only use the checkout action once.smac89
@smac89 many thanks to you, I still have one question: I am using > $GITHUB_REF to give each build a tag that identity it. I am looking for an env value that equals > $CIRCLE_BUILD_NUM in circlecisuliman
I don't think so, but you may try GITHUB_SHA. This is where all the default variables are definedsmac89
@smac89 thanks man I actually faced another issue after doing what you have suggested, I edited the question [link] (stackoverflow.com/q/58920140/10420300)suliman
Please ask a new question and link it here.smac89

1 Answers

3
votes

You only need to use actions/checkout once at the start of your workflow. When you use it again after building I think it's probably resetting your local workspace back to the GITHUB_SHA and your jar file is being deleted in the process.

Try this:

name: Java CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - run: gradle wrapper

      - run: ./gradlew bootJar

      - run: ls ./build/libs/

      - name: Login to docker
        run: docker login docker.pkg.github.com -u xxxxxx -p xxxxxx

      - name: Build the Docker image
        run: docker build . -t realtimechat-snapshot-0.$GITHUB_REF

      - name: Tag the image
        run: docker tag realtimechat-snapshot-0.$GITHUB_REF realtimechat-snapshot-0

      - name: Push the image
        run: docker push realtimechat-snapshot-0.$GITHUB_REF