Create a NuGet repo in JFrog Artifactory with GitHub Actions - github-actions

Aim: Create nuget package repository in JFrog Artifactory for .NET Core library.
Current status: I'm trying to create repo(nuget type) with use of repo-template in JFrog artifactory(those are few lines of code in GitHub actions *.yml file):
- name: Repository Creation
working-directory: templates
run: |
jf rt rc virtual-repo-template.json --vars "key1=test"
I get error: 403, Forbidden.
While creating docker image and pushing it into Artifactory Packages goes all well.

Related

GitHub Action to publish assets

I have one GitHub Action that is transforming a design tokens json file into a CSS file containing variables. That is working ok.
I have another yml file that only starts up after the first workflow has finished:
name: Package
# Only trigger, when the transform workflow succeeded
on:
workflow_run:
workflows: ["transform"]
types:
- completed
jobs:
publish-gpr:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
I just want to publish the CSS file as a package on GitHub Packages or NPM.
I am getting the following error:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`
Try adding the publishConfig to your package.json file:
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
}
Also, please make sure that your package is scoped:
"name": "#<gh-user-or-org>/<repo>"
Make sure that your package-lock.json is also updated (since the npm ci command relies on it). For more details, read the Publishing a package.
To publish your package to the regular NPM registry you need to store your npm authentication token as a secret. For example, create a repository secret called NPM_TOKEN. For more information, see Creating and using encrypted secrets.
To generate an npm token, you need to log in to your npmjs.com account, click your Profile picture > Access Tokens > Generate New Token > Classic Token. Make sure to choose the Automation token type.
After creating a repository secret with the npm token, make sure to update the workflow:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Unable to publish nuget package - github actions

I've built a github action to push my nuget package to github registry based on github docs. When it runs it compiles well but on push it runs to the following error.
Pushing XXXXX.1.0.0.nupkg to 'https://nuget.pkg.github.com/MYACCOUNT'
PUT https://nuget.pkg.github.com/MYACCOUNT/ warn : invalid repo host
'nuget.pkg.github.com', only github (github.com) repositories allowed BadRequest
https://nuget.pkg.github.com/MYACCOUNT/ 42ms error: Response status code does not indicate success: 400 (Bad Request).
Error message is not too verbose.
Api-key is registered in Personal access tokens. It has write/read:packages and full control of private repository permission.
What do I miss here?
Related yaml is the following:
name: publish to nuget
on:
push:
branches:
- master
jobs:
publish:
name: build, pack & publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Pack
run: dotnet pack XXX.csproj -c Release
- name: Prep packages
run: dotnet nuget add source --username MYACOUNTNAME --password *** --store-password-in-clear-text --name github "https://nuget.pkg.github.com/MYACCOUNTNAME/index.json"
- name: Publish to GitHub packages
run: dotnet nuget push bin/Release/*.nupkg --api-key *** --source "github"
For those who are concerned. After hours of struggle I found the problem.
I had to modify my .csproj file.
<RepositoryUrl>https://github.com/MYACCOUNTNAME/EXACT_REPOSITORY_NAME</RepositoryUrl>
My issues was that root url was https://nuget.pkg.github.com instead of github.com alone.
What a dumb error message...

Unable to resolve jar dependency in Java project for

I have 2 java projects on GitHub, the first project produces a java library and the second project uses it.
The first project is build via first job in yaml file and it installs the library in /home/runner/.m2/repository/ successfully
Then when the second project is build via the second job in the same yaml file , it fails with error
Failed to execute goal on project <>: Could not resolve dependencies
for project Could not find artifact <>:jar:1.0-
SNAPSHOT -> [Help 1]
In my second project, I have included the dependency to load this library jar(produced by first project) from the repository.
MY understanding is that my second project should load the jar library from the /home/runner/.m2/repository/ but its not loading it.
Any help is appreciated.
Also can we access /home/runner/.m2/repository/ to check if it contains the library jar.
./project_account_library/account_library => Contains maven project
./project_account_service/account_service => Contains maven project
./.github/workflows/build.yml
Here is the yml file
name: Build account service
on:
push:
branches: [main]
env:
IMAGE_NAME: accountservice
jobs:
build_dependency:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Build Dependency
run: |
cd ./project_account_library/account_library
mvn clean install
build_accountservice:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout#v2
- uses: actions/setup-java#v2
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
- name: Build Account Service
run: |
cd ./project_account_service/account_service
mvn clean install
First Step
[INFO] Installing /home/runner/work/<>/<>/target/account_
library_1.0-SNAPSHOT.jar to
/home/runner/.m2/repository/com/<>/<>/account_library/1.0-
SNAPSHOT/account_library-1.0-SNAPSHOT.jar
Second Step
Error: Failed to execute goal on project <>: Could not resolve
dependencies for project <>: Could not find artifact com.<>.
<>:account_library:jar:1.0-SNAPSHOT -> [Help 1]
Thanks Frennky
I now used only 1 job and below is my new .yml file
- name: Build Account Service
run: |
cd ./project_account_library/account_library
mvn clean install
cd ../../project_account_service/account_service
mvn clean install
First directory is successfully built but it fails to cd to ../../project_account_service/account_service and fails to build with below error
/home/runner/work/_temp/ea229141-b0c3-455d-82f0-12ff588d420a.sh: line 12: cd ../../project_account_service/account_service: No such file or directory
The reason you're missing dependencies on your second job is because those 2 jobs, by default, run in parallel and they do so on 2 different runners. From docs:
Each job will run inside its own virtual machine runner, or inside a
container...
There's few ways you can go around this. I can suggest one quick and easy, and another that would probably be a way to go, but require slightly more effort.
Easy way out of this is to put all steps in a single job.
Better way would be to make use of Github Package repository, where
you could push your lib/dependencies and then resolve them for your
service.
For more details on Github Package repository you can check docs.
Update:
Ok, I've reread your new error and I think I understand the issue.
If I got it right your dir structure is as follows:
repo
project_account_library
account_library
project_account_service
account_service
Each run step actually starts at root of you repo. You can use working-directory like so:
# ...
- name: Build Dependency
run: mvn clean install
working-directory: ./project_account_library/account_library
# ...
- name: Build Account Service
run: mvn clean install
working-directory: ./project_account_service/account_service

EB CLI parameterize deployment artifact name for CI deploys

Using EB CLI to deploy a prebuilt application package. The related config.yml section looks like this:
deploy:
artifact: Website.zip
The CI build however creates a file that has the version added to it:
Website-1.5.44.zip
Is there any option to specify the deployment artifact via command like, something like this:
eb deploy --artifact "Website-1.5.44.zip"
#or
eb deploy --artifact "/path/to/Website-1.5.44.zip"
Are there any alternatives that EB CLI provides to deploy versioned build artifacts in CI pipelines? I could probably renamed the versioned zip file to just Website.zip and then run eb deploy but it would be nice to have the version be present in the artifact filename also.
Currently there is no way to do what you are describing; there are no flags to direct the EB CLI to take from a custom artifact. For now you will have to name the artifact to whatever is in your config.yml
The comment that you added will save the artifact Website.zip and name the application version Website-1.5.44.zip. It will not deploy the artifact named Website-1.5.44.zip
This python script can help you
import os
print("creating website.zip (see eb config.yml)")
os.system("cp target/"+"website-"+version+".zip target/website.zip")
print("done.")
print("Deploying Version : "+"website-"+version+" to EB.... (uploading website.zip)")
os.system("eb deploy)
It seems that in 2022 it is still not possible.
In my case I've decided to edit .elasticbeanstalk/config.yml before deployment.
This is what the configuration looks like in the file:
deploy:
artifact: build/%PACKAGE_NAME%
Command I am using to replace %PACKAGE_NAME%:
sed -i "s/%PACKAGE_NAME%/$(find build/ -name '*.zip' -printf "%f")/1" .elasticbeanstalk/config.yml
sed -i is used to replace string %PACKAGE_NAME% in file .elasticbeanstalk/config.yml with the result of find command.
The label flag will rename the file uploaded to AWS:
eb deploy --label Website-1.5.44.zip

Bitbucket Pipelines config for yii2. Need github token

I am trying to use bitbucket pipelines for my project, and i use simple config:
image: phpunit/phpunit:5.0.3
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- composer --version
- phpunit --version
- composer global require "fxp/composer-asset-plugin:^1.2.0"
- composer install
- php init --env=Development --overwrite=All
But, at composer intall stage, i needs a github token, because yii2 is on github.
So, how to run composer with token, using this config ?
It should be enough to set some configuration for Composer. A link what command(s) to use: API rate limit and OAuth tokens. Simple steps:
Create an account on Github. You will get something like acd276d00a9de5a15743b7a0a33e39c0e7b8aed8. Be sure to make a note as you will not be able to look at it after some time.
Use Composer terminal (Git, for example) and enter command:
composer config -g github-oauth.github.com <oauthtoken>
Where <oauthtoken> is your token.
It should be configured now and Composer should now allow you to install.