Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
Adds automated testing on PR / Fix WHL push for PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
udondan authored Jan 19, 2020
1 parent f237f5d commit bde8060
Show file tree
Hide file tree
Showing 17 changed files with 1,381 additions and 33 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ LICENSE
Makefile
README.md
VERSION
test
67 changes: 67 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: Test image functionality

on:
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::$(cat VERSION)1$(( $RANDOM % 1000 ))

- name: Build the Docker image
run: docker build . --file Dockerfile --tag jsii-publish:current

- name: Build the test package
run: >-
docker run
--workdir /workdir
--volume ${PWD}/test:/workdir
--env VERSION=${{ steps.get_version.outputs.VERSION }}
--env BUILD_SOURCE=true
--env BUILD_PACKAGES=true
jsii-publish:current
- name: Publish to npm
run: >-
docker run
--workdir /workdir
--volume ${PWD}/test:/workdir
--env NPM_TOKEN="${{ secrets.NPM_TOKEN }}"
jsii-publish:current
- name: Publish to PyPI
run: >-
docker run
--workdir /workdir
--volume ${PWD}/test:/workdir
--env PYPI_TOKEN="${{ secrets.PYPI_TOKEN }}"
jsii-publish:current
- name: Publish to NuGet
run: >-
docker run
--workdir /workdir
--volume ${PWD}/test:/workdir
--env NUGET_TOKEN="${{ secrets.NUGET_TOKEN }}"
jsii-publish:current
- name: Publish to Maven GitHub
run: >-
docker run
--workdir /workdir
--volume ${PWD}/test:/workdir
--env GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"
--env GITHUB_REPOSITORY="${{ github.repository }}"
jsii-publish:current
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test/dist
test/node_modules
test/tsconfig.json
test/lib/*.js
test/lib/*.d.ts
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Package building and publishing to npm, PyPI, NuGet and Maven (GitHub).

## Examples

### Usage in a GitHub workflow
### GitHub workflow

```yml
---
Expand All @@ -36,7 +36,7 @@ jobs:
fetch-depth: 1

- name: Publish packages
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
VERSION: ${{ steps.get_version.outputs.VERSION }}
BUILD_SOURCE: true
Expand Down Expand Up @@ -74,39 +74,39 @@ jobs:
fetch-depth: 1

- name: Build source
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
VERSION: ${{ steps.get_version.outputs.VERSION }}
BUILD_SOURCE: true

- name: Build packages
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
BUILD_PACKAGES: true

- name: Publish to npm
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to PyPI
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

- name: Publish to NuGet
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}

- name: Publish to Maven GitHub
uses: udondan/[email protected].2
uses: udondan/[email protected].3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
```
### Usage for running the Docker image locally
### Running the Docker image locally
```bash
docker run -it \
Expand All @@ -120,7 +120,7 @@ docker run -it \
--env NUGET_TOKEN \
--env GITHUB_TOKEN \
--env GITHUB_REPOSITORY="${OWNER}/${REPOSITORY}" \
udondan/jsii-publish:0.8.2
udondan/jsii-publish:0.8.3
```

The package code can be mounted to any location in the container. Just make sure you set the workdir to the same value. In the example above I use `/workdir`.
Expand All @@ -135,7 +135,7 @@ Parameters passed per env:
- **NUGET_TOKEN**: Your publish token for NuGet. If passed, package will be published to NuGet
- **GITHUB_TOKEN**: The token to interact with GitHub. If passed, the Maven package will be published to GitHub packages.
If you run the GitHub action, the token will be automatically be generated byu GitHub and is available as `${{ GITHUB_TOKEN }}`. If you run the Docker image yourself, you need to pass in a [personal access token](https://github.com/settings/tokens) with `read:packages` and `write:packages` capabilities.
- **GITHUB_REPOSITORY**: The url slug of your repository, which is `${OWNER}/${REPOSITORY}`. In a github action you can just pass `${{ GITHUB_REPOSITORY }}`.
- **GITHUB_REPOSITORY**: The url slug of your repository, which is `${OWNER}/${REPOSITORY}`. In a github action you can just pass `${{ github.repository }}`.
- **DEBUG**: If `true`, debug mode is enabled. **Might leak secrets in output**.

## License
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.2
0.8.3
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:
color: orange
runs:
using: docker
image: docker://udondan/jsii-publish:0.8.2
image: docker://udondan/jsii-publish:0.8.3
inputs:
BUILD_SOURCE:
description: Indicates if the source should be build (tsc)
Expand All @@ -31,7 +31,7 @@ inputs:
description: Your publish token for GitHub. If passed, Maven package will be published to Github
required: false
GITHUB_REPOSITORY:
description: GitHub repository path. OWNER/REPO, e.g. "udondan/jsii-publish"
description: GitHub repository path. OWNER/REPO, e.g. "udondan/jsii-publish". You can just pass in "{{ github.repository }}"
required: false
DEBUG:
description: Enables debug mode
Expand Down
37 changes: 28 additions & 9 deletions scripts/entrypoint
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash

# All env vars that can be passed in, are handled in two variants
# FOO which can be passed in by the user when running locally
# INPUT_FOO, which is the prefixed version passed in by GitHub actions

set -euo pipefail
IFS=$'\n\t'

Expand All @@ -28,6 +24,11 @@ complete() {
print "✅ Done"
}

# All env vars that can be passed in, are handled in two variants
# FOO, which can be passed in by the user when running locally
# INPUT_FOO, which is the prefixed version passed in by GitHub actions
# The var function covers both cases. Furthermore it converts the variable to
# a boolean, if the 2nd parameter is true
var() {
local name="$1"
local value
Expand All @@ -47,10 +48,28 @@ var() {
fi
}

# Fails if the var named in 1st param is undefined/empty
require() {
[ -z "${!1}" ] && error "$1 required"
return 0
}

# Fails if the string given in 1st param is not a directory
require_dir() {
[ ! -d "$1" ] && error "Require target directory as first parameter"
return 0
}

require_file() {
[ ! -f "$2" ] && error "Require target file as first parameter"
[ "${2##*.}" != "$1" ] && error "Target file needs to be of type $1, got ${2##*.}"
return 0
}

var DEBUG true
var VERSION
var BUILD_SOURCE true
var BUILD_PACKAGES
var BUILD_PACKAGES true
var NPM_TOKEN
var PYPI_TOKEN
var NUGET_TOKEN
Expand All @@ -66,19 +85,19 @@ source <(cat /scripts/publish/*)

# Update the version if it was passed
if [[ -n "${VERSION}" ]]; then
print "Updating package version to $VERSION..."
print "Updating package version to ${VERSION}..."
npm version "${VERSION}" --allow-same-version --no-git-tag-version
fi

if [[ "${BUILD_SOURCE}" == "true" || "${BUILD_SOURCE}" == "yes" ]]; then
if [[ "${BUILD_SOURCE}" = true ]]; then
print "Installing dependencies..."
npm install

print "Building source..."
npm run build
fi

if [[ "${BUILD_PACKAGES}" == "true" || "${BUILD_PACKAGES}" == "yes" ]]; then
if [[ "${BUILD_PACKAGES}" = true ]]; then
print "Building packages..."
rm -rf dist/*
npm run package
Expand All @@ -88,7 +107,7 @@ fi
[ -n "${NPM_TOKEN}" ] && publish_to_npm dist/js/*

# Publish to PyPI if token is present
[ -n "${PYPI_TOKEN}" ] && publish_to_pypi dist/python/*
[ -n "${PYPI_TOKEN}" ] && publish_to_pypi dist/python

# Publish to NuGet if token is present
[ -n "${NUGET_TOKEN}" ] && publish_to_nuget dist/dotnet/*.nupkg
Expand Down
6 changes: 3 additions & 3 deletions scripts/publish/maven
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

publish_to_maven() {
begin Maven
[ ! -d "${1:-}" ] && error "Require target directory as first parameter"
[ -z "${GITHUB_TOKEN:-}" ] && error "GITHUB_TOKEN required"
[ -z "${GITHUB_REPOSITORY:-}" ] && error "GITHUB_REPOSITORY required"
require_dir "${1:-}"
require GITHUB_TOKEN
require GITHUB_REPOSITORY
GITHUB_REPOSITORY=$(echo "${GITHUB_REPOSITORY:-}" | tr '[:upper:]' '[:lower:]')

cd "${1:-}" || exit
Expand Down
4 changes: 2 additions & 2 deletions scripts/publish/npm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

publish_to_npm() {
begin npm
[ -z "${1:-}" ] && error "Require target directory as first parameter"
[ -z "${NPM_TOKEN:-}" ] && error "NPM_TOKEN required"
require_file tgz "${1:-}"
require NPM_TOKEN

echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc

Expand Down
4 changes: 2 additions & 2 deletions scripts/publish/nuget
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

publish_to_nuget() {
begin NuGet
[ -z "${1:-}" ] && error "Require target directory as first parameter"
[ -z "${NUGET_TOKEN:-}" ] && error "NUGET_TOKEN required"
require_file nupkg "${1:-}"
require NUGET_TOKEN

cmd=(dotnet nuget)
if [[ "${DEBUG}" = true ]]; then
Expand Down
6 changes: 3 additions & 3 deletions scripts/publish/pypi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

publish_to_pypi() {
begin PyPI
[ -z "${1:-}" ] && error "Require target directory as first parameter"
[ -z "${PYPI_TOKEN:-}" ] && error "PYPI_TOKEN required"
require_dir "${1:-}"
require PYPI_TOKEN

cat <<EOF > ~/.pypirc
[pypi]
Expand All @@ -15,7 +15,7 @@ EOF
if [[ "${DEBUG}" = true ]]; then
cmd+=(--verbose)
fi
cmd+=("$1")
cmd+=("$1/*")

eval "${cmd[@]}"

Expand Down
Loading

0 comments on commit bde8060

Please sign in to comment.