I run tests on GitHub Actions, like this:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch#master
with:
stack-version: 7.16.1
- name: Set up JDK 17
uses: actions/setup-java#v1
with:
java-version: 17
- name: Build with Maven
run: mvn -B package --file pom.xml
The version of ElasticSearch is currently fixed; but in my project I include the ElasticSearch client 7.16.3. I would like to use that version in the stack-version as well. Is there a preferred way to extract a property from the pom.xml and use that in the Action?
You can use get-xml-info to read a property from the pom.xml
- name: Get elasticsearch version from pom.xml
id: get-elasticsearch-version
uses: mavrosxristoforos/get-xml-info#1.0
with:
xml-file: 'pom.xml'
xpath: '//*[local-name()="elasticsearch.version.property.tagname"]'
- name: Runs Elasticsearch
uses: elastic/elastic-github-actions/elasticsearch#master
with:
stack-version: ${{ steps.get-elasticsearch-version.outputs.info }}
Related
Need to automate sematic versioning with new releasetag creation with latest asset attach on github. I think need to workflow but not getting refernce
jobs:
release-project:
name: Release automation
runs-on: ubuntu-latest
needs: build_artifact
steps:
name: Download site content
uses: actions/download-artifact#v2
with:
name: 'testgitjar'
name: Archieve site content
uses: thedoctor0/zip-release#master
with:
filename: site.zip
name: create GitHub Release
id: create-new-release
uses: actions/create-release#v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.run_number }}
release_name: Release V${{ github.run_number }}
name: Upload asset to github Release
uses: actions/upload-release-asset#v1
env:
GITHUB_TOKEN: ${{ steps.create-new-release.outputs.upload_url }}
with:
upload_url: ${{ steps.create-new-release.outputs.upload_url }}
asset_path: ./site.zip
asset_name: site-v${{ github.run_number }}.zip
asset_content_type: application/zip
I have run Selenium Java tests via GitHub Actions. For generating Report I have used
dorny/test-reporter#v1.5.0
My .xml file is:
name: DEV Table View suite
on:
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Set up JDK 1.11
uses: actions/setup-java#v2
with:
java-version: '11'
distribution: 'adopt'
- name: Test
run: mvn clean test -Denv=DEV -DtestngXML='tableView.xml'
- name: Report
uses: dorny/test-reporter#v1.5.0
if: always()
with:
name: Maven Tests
path: "**/surefire-reports/TEST-*.xml"
reporter: java-junit
fail-on-error: false
But in results I have noticed some issues:
incorrect time
passed tests are not green-colored
How to solve these issues?
I'm currently on my final phase of my bachelor thesis, implementing a web application. Now I need to host it on Azure. I've an application.war with Angular Frontend in it and a services.war with the Java REST Calls. Both are packed through Maven.
When I deploy it from Github with GitHub Actions to Azure, I get the following Error:
"Deployment Failed with Error: Error: More than one package matched with specified pattern: *.war. Please restrain the search pattern."
Do you have a tutorial or can help me how to setup the yml-file to deploy the application.war to ROOT and services.war to /services/...
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Java version
uses: actions/setup-java#v1
with:
java-version: '11'
- name: Build with Maven
run: mvn clean install
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: java-app
path: '${{ github.workspace }}/**/target/*.war'
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: java-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'app-name'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
package: '*.war'
Thank you very much!
Janick
If you check this Deploy Angular app to Azure App Service running Linux from GitHub, you will understand how to deploy an Angular single page application, from GitHub to Azure App Service.
In order to deploy to App Service using GitHub Actions we need a workflow file. A workflow is defined by a YAML (.yml) file in the /.github/workflows/ path in your repository. This definition contains the various steps and parameters that make up the workflow.
Build and deploy a Java app to Azure using an Azure publish profile. The publish-profile input references the AZURE_WEBAPP_PUBLISH_PROFILE secret that you created earlier.
name: Java CI with Maven
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
working-directory: my-app-path
- name: Azure WebApp
uses: Azure/webapps-deploy#v2
with:
app-name: my-app-name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: my/target/*.war
For more information check this Deploy to App Service using GitHub Actions document from Microsoft. Also read this Create Azure Web App and deploy using GitHub Actions document from GitHub and check the example templates.
As the docs state in order to cache the Maven dependencies with GitHub Actions all we have to use is the actions/cache action like this:
steps:
- uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache#v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
However using the windows-2016 GitHub Actions environment, this doesn't provides us with a working cache - as the logs states:
Post job cleanup.
"C:\Program Files\Git\usr\bin\tar.exe" --posix --use-compress-program "zstd -T0" -cf cache.tzst -P -C D:/a/spring-boot-admin/spring-boot-admin --files-from manifest.txt --force-local
/usr/bin/tar: C\:\\Users\runneradmin\\.m2\repository: Cannot stat: No such file or directory
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Tar failed with error: The process 'C:\Program Files\Git\usr\bin\tar.exe' failed with exit code 2
How to fix this?
It seems that the path to the Maven repository isn't correctly initialized. As this issue describes the paths are written with \\ instead of / which GNU tar expects. The fix was already provided in Dec 2020, so it made it to the version v2.1.4. The last version v2.1.3 was released in November. But sadly there is a bug in pointing the v2 to the latest v2.1.4 (as normally expected by GitHub Actions users). Therefore to solve this issue, we need to explicitely specifiy the full actions/cache version v2.1.4 like this:
steps:
- uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache#v2.1.4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
Now it should work like a charm (see logs here).
I'm working on a project where we use Firebase to store data and we're doing some unit tests. I have set a GitHub Action that executes mvn package and mvn test on every push or pull request, and the problem is that I receive the following error when it executes tests:
java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
I have created the secret with the .json and this is how I wrote the GitHub Action:
name: Maven CI/CD
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 15
uses: actions/setup-java#v1
with:
java-version: 15
- name: Cache the Maven packages to speed up build
uses: actions/cache#v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build project with Maven
run: mvn -B package --file pom.xml
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
- name: Run (J)Unit tests
run: mvn clean test
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
I have found that it somehow wasn't using the updated version of the action. Anyway, I solved using google-github-actions/setup-gcloud#master set as follow:
- uses: google-github-actions/setup-gcloud#master
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
- name: Set GCP credentials
run: gcloud info
GCP_PROJECT_ID contains the project id and GCP_SA_KEY contains the service account .json file obtained from Firebase.