1

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"

suliman
  • 334
  • 6
  • 17
  • Why are you checking out your repo over and over again? _Note there is an [issue](https://github.com/actions/checkout/issues/63) 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 Nov 18 '19 at 23:29
  • @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 circleci – suliman Nov 19 '19 at 15:41
  • I don't think so, but you may try `GITHUB_SHA`. [This](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables) is where all the default variables are defined – smac89 Nov 19 '19 at 15:48
  • @smac89 thanks man I actually faced another issue after doing what you have suggested, I edited the question [link] (https://stackoverflow.com/q/58920140/10420300) – suliman Nov 19 '19 at 15:53
  • Please ask a new question and link it here. – smac89 Nov 19 '19 at 15:54
  • Also in the future, you may want to use [secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#about-encrypted-secrets) to store your access tokens. You can retrieve the secret by calling `${{ secrets.MY_TOKEN }}`. As soon as you can, you should remove that access token you have above and use secrets instead. Note editing this question will not help because stackoverflow saves edit history, so you still should revoke that token and create a new one – smac89 Nov 19 '19 at 16:03
  • @smac89 many thanks in advance: (https://stackoverflow.com/questions/58938410/github-ci-error-parsing-http-404-response-body-when-pushing-the-image) – suliman Nov 19 '19 at 16:12

1 Answers1

3

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
peterevans
  • 34,297
  • 7
  • 84
  • 83