Skip to content

Commit

Permalink
Switching to us of GitHubActions module (#4)
Browse files Browse the repository at this point in the history
* removing local lib

* switching to module

* no need for local lib anymore

* Update ci.yml

* Removing lib-related docs since these are now moved to PS Module:

* checkout the docs at the [module GitHub](https://github.com/ebekker/pwsh-github-action-tools/blob/master/docs/GitHubActions/README.md).

* upgrading dependencies to latest, removing some defunct stuff

* updating reference to the module and the related docs

* updating name to better reflect module changes
  • Loading branch information
ebekker authored Aug 10, 2020
1 parent b19583a commit 6485cb7
Show file tree
Hide file tree
Showing 27 changed files with 741 additions and 1,152 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ jobs:
- name: pester tests
shell: pwsh
run: |
if (-not (Get-Module -ListAvailable Pester)) {
Install-Module Pester -Force
$neededModules = @(
'Pester'
'GitHubActions'
)
$neededModules | % {
if (-not (Get-Module -ListAvailable $_)) {
Install-Module $_ -Force
}
}
./tests/ActionCore_tests.ps1
./tests/GitHubActions_tests.ps1
# - name: bundle distributable components
# shell: pwsh
Expand All @@ -37,7 +43,6 @@ jobs:
run: |
mkdir ./dist
Copy-Item ./_init ./dist/ -Recurse
Copy-Item ./lib ./dist/ -Recurse
Copy-Item ./SAMPLE-* ./dist/
Copy-Item ./LICENSE ./dist/
Copy-Item ./README.md ./dist/
Expand All @@ -51,8 +56,7 @@ jobs:
path: ./dist

publish:
runs-on: ubuntu-16.04
#runs-on: ubuntu-latest
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release'
steps:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,8 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/


## Standard Ignores
_IGNORE/
_TMP/
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Base support for implementing GitHub Actions in PowerShell Core

[![GitHub Workflow - CI](https://github.com/ebekker/pwsh-github-action-base/workflows/CI/badge.svg)](https://github.com/ebekker/pwsh-github-action-base/actions?workflow=CI)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/ebekker/pwsh-github-action-base)](https://github.com/ebekker/pwsh-github-action-base/releases/latest/download/pwsh-github-action-base-dist.zip)
[![docs for lib/ActionsCore](https://img.shields.io/badge/docs-lib/ActionsCore-blueviolet)](docs/README.md)

---

Expand All @@ -18,16 +17,18 @@ The [distribution](https://github.com/ebekker/pwsh-github-action-base/releases/l

* **[`_init/index.js`](_init/index.js)** -
The entry point into invoking the Action.
* **[`lib/ActionsCore.ps1`](lib/ActionsCore.ps1)** -
A collection of cmdlets that support interfacing to the
Actions/Workflow environment for input, output and messaging.
* **[`SAMPLE-action.ps1`](SAMPLE-action.ps1)** -
A sample script implementing a simple Action script demonstrating some
of the features made available from the Core library.
* **[`SAMPLE-action.yml`](SAMPLE-action.yml)** -
A sample Action metadata file that describes various attributes such as a
description, licensing, branding and formal input and output values.

Additionally, the sample Action shows how to make use of the
[GitHubActions module](https://www.powershellgallery.com/packages/GitHubActions)
to get access to the GH Actions/Workflow environment for input, output
and messaging. More details can be found [below](#optional-support-module)

## Required Components

### `action.ps1` - The PowerShell Entry Point
Expand All @@ -43,25 +44,29 @@ the GitHub API.

### `action.yml` - The Action Metadata

As per the GitHub Actions mechanism, you must provide a [metadata file](https://help.github.com/en/articles/metadata-syntax-for-github-actions) that describes
various attributes about your Action, including any formal inputs and outputs.
You use this metadata file to enumerate any _required_ inputs that must be
provided by a Workflow definition.
As per the GitHub Actions mechanism, you must provide a
[metadata file](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
that describes various attributes about your Action, including any formal inputs
and outputs. You use this metadata file to enumerate any _required_ inputs that
must be provided by a Workflow definition.

##### `runs` Entry Point Attribute
#### `runs` Entry Point Attribute

The most important attribute in this file for our purposes is the `runs`
setting which has two child settings, `using` and `main`. This attribute
indicates what is the [_type_](https://help.github.com/en/articles/about-actions#types-of-actions) of your Action and how to run it.
indicates what is the
[_type_](https://help.github.com/en/articles/about-actions#types-of-actions)
of your Action and how to run it.

There are two main types of Actions, one based on Docker containers and
one based on JavaScript (NodeJS). While Docker Actions give you the ability
to define and _carry_ the entire runtime with you, they are slower to start
and limited to only executing in Linux environments.

JavaScript Actions however are simpler and more lightweight, and therefore
quicker to start, and they can run on any of the supported platforms (Linux, Windows, MacOS). They also execute directly in the hosted virtual machine
where the Workflow runs instead of a dedicated container.
quicker to start, and they can run on any of the supported platforms
(Linux, Windows, MacOS). They also execute directly in the hosted virtual
machine where the Workflow runs instead of a dedicated container.

Because of these advantages, this repo hosts a solution that is based on
JavaScript-type Actions. A stub JavaScript script is provided to bootstrap
Expand Down Expand Up @@ -99,15 +104,16 @@ The working directory is the same as at the start of the bootstrap
script which is the root of the cloned repository of the Workflow
in which the action is being invoked.

## Optional Support Library
## Optional Support Module

In addition to the required components above, you may choose to make use
of the **[`lib/ActionsCore.ps1`](lib/ActionsCore.ps1)** utility script that
defines a number of cmdlets that help interact with the Worklfow/Action
environment context in a more natural way for PowerShell scripts.
These cmdlets are adaptations of the JavaScript Actions
In addition to the required components above, you may choose to make use of the
**[`GitHubActions` PowerShell module](https://www.powershellgallery.com/packages/GitHubActions)**
utility script that defines a number of cmdlets that help interact with the
Worklfow/Action environment context in a more natural way for PowerShell
scripts. These cmdlets are adaptations of the JavaScript Actions
[core package](https://github.com/actions/toolkit/tree/master/packages/core) provided in the
[Actions Toolkit](https://github.com/actions/toolkit). See that package
description for details about what it provides

For details about the counterpart cmdlets, go to the [docs](docs/README.md).
For details about the counterpart cmdlets, go to the
[docs](https://github.com/ebekker/pwsh-github-action-tools/blob/master/docs/GitHubActions/README.md).
18 changes: 14 additions & 4 deletions SAMPLE-action.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
## This is a sample GitHub Action script written in PowerShell Core.
## You can write your logic in PWSH to perform GitHub Actions.
##


## You interface with the Actions/Workflow system by interacting
## with the environment. The `ActionsCore.ps1` library makes this
## easier and more natural.
##
## with the environment. The `GitHubActions` module makes this
## easier and more natural by wrapping up access to the Workflow
## environment in PowerShell-friendly constructions and idioms
if (-not (Get-Module -ListAvailable GitHubActions)) {
## Make sure the GH Actions module is installed from the Gallery
Install-Module GitHubActions -Force
}

## Load up some common functionality for interacting
## with the GitHub Actions/Workflow environment
. ./lib/ActionsCore.ps1
Import-Module GitHubActions

##
## ***** Put your logic here *****
##

## Pull in some inputs
$salutation = Get-ActionInput salutation -Required
Expand Down
Loading

0 comments on commit 6485cb7

Please sign in to comment.