ci: Package action automatically on release branch (#15)

This commit is contained in:
Samuel Ryan 2022-12-02 16:37:11 +00:00 committed by GitHub
parent abde1147dd
commit 917745b929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 1623 deletions

19
.github/workflows/build_action.yaml vendored Normal file
View file

@ -0,0 +1,19 @@
name: "Build Action (if not available)"
on: [workflow_call]
jobs:
build-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- name: Build action (if not already built)
if: "!startsWith(github.ref, 'refs/heads/release')"
run: npm run build
- name: Push build into cache
if: "!startsWith(github.ref, 'refs/heads/release')"
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}

View file

@ -3,11 +3,20 @@ name: Test Directory Extraction
on: [push]
jobs:
action:
uses: ./.github/workflows/build_action.yaml
root-directory:
runs-on: ubuntu-latest
needs:
- action
name: Extract Contents of Directory from Example Image
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
@ -22,9 +31,16 @@ jobs:
- run: test -e ${{ steps.extract.outputs.destination }}/y/006.txt || exit 1
nested-directory:
runs-on: ubuntu-latest
needs:
- action
name: Extract Nested Directory from Example Image
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
@ -35,9 +51,16 @@ jobs:
- run: test -e ${{ steps.extract.outputs.destination }}/x/005.txt || exit 1
nested-directory-contents:
runs-on: ubuntu-latest
needs:
- action
name: Extract Nested Contents of Directory from Example Image
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract

View file

@ -3,11 +3,20 @@ name: Test File Extraction
on: [push]
jobs:
action:
uses: ./.github/workflows/build_action.yaml
root-file:
runs-on: ubuntu-latest
needs:
- action
name: Extract Example File From Root of Built Image
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
@ -17,9 +26,16 @@ jobs:
- run: test -e ${{ steps.extract.outputs.destination }}/001.txt || exit 1
nested-file:
runs-on: ubuntu-latest
needs:
- action
name: Extract Nexted Example File From Built Image
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract

35
.github/workflows/package-action.yaml vendored Normal file
View file

@ -0,0 +1,35 @@
name: "Package Action"
on:
push:
branches:
- "main"
env:
source: "main"
release: "release"
jobs:
package-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: "${{ env.release }}"
fetch-depth: 0
ssh-key: "${{ secrets.COMMIT_KEY }}"
- uses: pr-mpt/actions-merge-branch@v2
with:
from: "origin/${{ env.source }}"
commit: false
- name: Install Javascript dependencies with npm
run: npm install
- name: Package action for distribution
run: npm run package
- name: Push packaged action to branch
uses: EndBug/add-and-commit@v7
with:
add: "['.', 'dist --force']"
branch: "${{ env.release }}"
default_author: github_actions
message: "build: Package action as `dist` with latest changes"

View file

@ -3,11 +3,20 @@ name: Test Cross Platform Support
on: [push]
jobs:
action:
uses: ./.github/workflows/build_action.yaml
linux:
runs-on: ubuntu-latest
needs:
- action
name: Extract Example File on Ubuntu
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- run: docker build -t example:${{ github.sha }} ./.github/tests
- uses: ./
id: extract
@ -17,9 +26,16 @@ jobs:
- run: test -e ${{ steps.extract.outputs.destination }}/001.txt || exit 1
macos:
runs-on: macos-latest
needs:
- action
name: Extract Example File on macOS
steps:
- uses: actions/checkout@v2
- name: Load action build from cache
uses: actions/cache@v3
with:
path: dist
key: build-${{ github.sha }}
- name: Install Docker
env:
HOMEBREW_GITHUB_API_TOKEN: "${{ github.token }}"

22
.github/workflows/validate-tag.yaml vendored Normal file
View file

@ -0,0 +1,22 @@
name: "Limit Tags To Distributable Commits"
on:
push:
tags:
- "**"
jobs:
validate-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ssh-key: "${{ secrets.COMMIT_KEY }}"
- name: Test that the tagged commit includes `dist`
uses: pr-mpt/actions-assert@v2
with:
assertion: npm://@assertions/directory-exists
expected: dist
- if: failure()
name: Delete invalid tag
uses: pr-mpt/actions-delete-tag@v1

1
.gitignore vendored
View file

@ -1 +1,2 @@
node_modules/
/dist/

View file

@ -5,27 +5,27 @@ A GitHub Action for extracting files from a Docker Image.
```yaml
- uses: shrink/actions-docker-extract@v1
with:
image: 'ghost:alpine'
path: '/var/lib/ghost/current/core/built/assets/.'
image: "ghost:alpine"
path: "/var/lib/ghost/current/core/built/assets/."
```
## Inputs
All inputs are required.
| ID | Description | Examples |
| --- | ----------- | -------- |
| `image` | Docker Image to extract files from | `alpine` `ghcr.io/github/super-linter:latest` |
| `path` | Path (from root) to a file or directory within Image | `files/example.txt` `files` `files/.` |
| ID | Description | Examples |
| ------- | ---------------------------------------------------- | --------------------------------------------- |
| `image` | Docker Image to extract files from | `alpine` `ghcr.io/github/super-linter:latest` |
| `path` | Path (from root) to a file or directory within Image | `files/example.txt` `files` `files/.` |
> :paperclip: To copy the **contents** of a directory the `path` must end with
`/.` otherwise the directory itself will be copied. More information about the
specific rules can be found via the [docker cp][docker-cp] documentation.
> `/.` otherwise the directory itself will be copied. More information about the
> specific rules can be found via the [docker cp][docker-cp] documentation.
## Outputs
| ID | Description | Example |
| --- | ----------- | ------- |
| ID | Description | Example |
| ------------- | ------------------------------------------------- | ------------------------ |
| `destination` | Destination path containing the extracted file(s) | `.extracted-1598717412/` |
## Examples
@ -88,6 +88,25 @@ jobs:
name: dist
```
## Automatic Release Packaging
A Workflow packages the Action automatically when a collaborator created a new
tag. Any reference to this Action in a Workflow must use a [tag][tags] (mutable)
or the commit hash of a tag (immutable).
```yaml
✅ uses: shrink/actions-docker-extract@v2
✅ uses: shrink/actions-docker-extract@v2.0.0
✅ uses: shrink/actions-docker-extract@abde1147dd0d248b38feda9e75768c3d2b57eefc
❌ uses: shrink/actions-docker-extract@main
```
The blog post
[Package GitHub Actions automatically with GitHub Actions][blog/package-automatically]
describes how this is achieved.
[build-push-action]: https://github.com/docker/build-push-action
[login-action]: https://github.com/docker/login-action
[docker-cp]: https://docs.docker.com/engine/reference/commandline/cp/#extended-description
[tags]: https://github.com/shrink/actions-docker-extract/tags
[blog/package-automatically]: https://medium.com/prompt/package-github-actions-automatically-with-github-actions-a70b9f7bae4

1613
dist/index.js vendored

File diff suppressed because it is too large Load diff