Skip to content

Commit

Permalink
Setup the pack-and-push-nuget github action
Browse files Browse the repository at this point in the history
  • Loading branch information
albelli-cicd-automation authored and Sergii Kolbasin committed Nov 15, 2021
0 parents commit 9e16459
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright 2021 Albelli BV

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pack And Push NuGet Package To NuGet Server

A GitHub Action to pack and push a [nuget package](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push).

You could use [albumprinter/actions-get-git-version](https://github.com/albumprinter/actions-get-git-version) to get the semver using git log.

## Usage

```yaml
- uses: albumprinter/actions-pack-and-push-nuget@v1
with:
package: YOUR_PACKAGE_NAME
description: YOUR_PACKAGE_DESCRIPTION
version: YOUR_PACKAGE_VERSION or ${{ steps.git-version.outputs.version }}
paths: dist deploy.sh
server: ${{ secrets.ARTIFACTORY_DEPLOY_RELEASE_URL }}
username: ${{ secrets.ARTIFACTORY_USERNAME }}
password: ${{ secrets.ARTIFACTORY_USER_PASSWORD }}
```
54 changes: 54 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# https://docs.github.com/en/actions/creating-actions/about-custom-actions

name: Pack And Push NuGet Package
description: Pack a nuget package and push it to the nuget server.

inputs:
package:
description: nuget package name
required: true

description:
description: nuget package description
required: true

version:
description: nuget package version
required: true

authors:
description: nuget package authors
required: false
default: 'Albelli'

paths:
description: paths to files to be packaged in the nuget package
required: true

server:
description: nuget api url
required: true

username:
description: nuget username
required: true

password:
description: nuget password
required: true

runs:
using: composite
steps:
- name: pack nuget package and publish it to the nuget server
shell: bash
run: |
PR_BRANCH=${GITHUB_HEAD_REF}
PUSH_BRANCH=${GITHUB_REF#refs/heads/}
BRANCH="${PR_BRANCH:-${PUSH_BRANCH}}"
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><package xmlns=\"http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd\"><metadata><id>${{ inputs.package }}</id><version>${{ inputs.version }}</version><authors>${{ inputs.authors }}</authors><description>${{ inputs.description }}</description></metadata></package>" > config.nuspec
echo "{\"build\":\"${{ inputs.version }}\", \"branch\":\"$BRANCH\"}" > info.json
zip -r ${{ inputs.package }}.nupkg config.nuspec info.json ${{ inputs.paths }}
dotnet nuget add source ${{ inputs.server }} -n albelli -u ${{ inputs.username }} -p ${{ inputs.password }} --store-password-in-clear-text
dotnet nuget push ${{ inputs.package }}.nupkg -s albelli --skip-duplicate --api-key ${{ inputs.username }}:${{ inputs.password }} --timeout 15

0 comments on commit 9e16459

Please sign in to comment.