mirror of
https://github.com/dagger/dagger-for-github.git
synced 2026-01-01 05:00:21 +11:00
Initial commit
This commit is contained in:
commit
aecf5e3748
30 changed files with 9832 additions and 0 deletions
2
.dockerignore
Normal file
2
.dockerignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/coverage
|
||||
/node_modules
|
||||
18
.editorconfig
Normal file
18
.editorconfig
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# This file is for unifying the coding style for different editors and IDEs.
|
||||
# More information at http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[test/**]
|
||||
insert_final_newline = false
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/dist/** linguist-generated=true
|
||||
/lib/** linguist-generated=true
|
||||
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
* @crazy-max
|
||||
32
.github/CONTRIBUTING.md
vendored
Normal file
32
.github/CONTRIBUTING.md
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
## Contributing
|
||||
|
||||
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
|
||||
|
||||
Contributions to this project are [released](https://docs.github.com/en/github/site-policy/github-terms-of-service#6-contributions-under-repository-license)
|
||||
to the public under the [project's open source license](LICENSE).
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork](https://github.com/crazy-max/dagger-action/fork) and clone the repository
|
||||
2. Configure and install the dependencies: `yarn install`
|
||||
3. Create a new branch: `git checkout -b my-branch-name`
|
||||
4. Make your changes
|
||||
5. Make sure the tests pass: `docker buildx bake test`
|
||||
6. Format code and build javascript artifacts: `docker buildx bake pre-checkin`
|
||||
7. Validate all code has correctly formatted and built: `docker buildx bake validate`
|
||||
8. Push to your fork and [submit a pull request](https://github.com/crazy-max/dagger-action/compare)
|
||||
9. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
||||
|
||||
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
|
||||
|
||||
- Write tests.
|
||||
- Make sure the `README.md` and any other relevant **documentation are kept up-to-date**.
|
||||
- We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
|
||||
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as **separate pull requests**.
|
||||
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
||||
|
||||
## Resources
|
||||
|
||||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
||||
- [Using Pull Requests](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests)
|
||||
- [GitHub Help](https://docs.github.com/en)
|
||||
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
github: crazy-max
|
||||
custom: https://www.paypal.me/crazyws
|
||||
29
.github/SUPPORT.md
vendored
Normal file
29
.github/SUPPORT.md
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Support [](https://isitmaintained.com/project/crazy-max/dagger-action)
|
||||
|
||||
## Reporting an issue
|
||||
|
||||
Please do a search in [open issues](https://github.com/crazy-max/dagger-action/issues?utf8=%E2%9C%93&q=) to see if the issue or feature request has already been filed.
|
||||
|
||||
If you find your issue already exists, make relevant comments and add your [reaction](https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments). Use a reaction in place of a "+1" comment.
|
||||
|
||||
:+1: - upvote
|
||||
|
||||
:-1: - downvote
|
||||
|
||||
If you cannot find an existing issue that describes your bug or feature, submit an issue using the guidelines below.
|
||||
|
||||
## Writing good bug reports and feature requests
|
||||
|
||||
File a single issue per problem and feature request.
|
||||
|
||||
* Do not enumerate multiple bugs or feature requests in the same issue.
|
||||
* Do not add your issue as a comment to an existing issue unless it's for the identical input. Many issues look similar, but have different causes.
|
||||
|
||||
The more information you can provide, the more likely someone will be successful reproducing the issue and finding a fix.
|
||||
|
||||
You are now ready to [create a new issue](https://github.com/crazy-max/dagger-action/issues/new/choose)!
|
||||
|
||||
## Closure policy
|
||||
|
||||
* Issues that don't have the information requested above (when applicable) will be closed immediately and the poster directed to the support guidelines.
|
||||
* Issues that go a week without a response from original poster are subject to closure at my discretion.
|
||||
18
.github/dependabot.yml
vendored
Normal file
18
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
labels:
|
||||
- ":game_die: dependencies"
|
||||
- ":robot: bot"
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
allow:
|
||||
- dependency-type: "production"
|
||||
labels:
|
||||
- ":game_die: dependencies"
|
||||
- ":robot: bot"
|
||||
96
.gitignore
vendored
Normal file
96
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/.dev
|
||||
node_modules/
|
||||
lib
|
||||
|
||||
# Jetbrains
|
||||
/.idea
|
||||
/*.iml
|
||||
|
||||
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 CrazyMax
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
100
README.md
Normal file
100
README.md
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
[](https://github.com/crazy-max/dagger-action/releases/latest)
|
||||
[](https://github.com/marketplace/actions/dagger-action)
|
||||
[](https://github.com/crazy-max/dagger-action/actions?workflow=test)
|
||||
[](https://codecov.io/gh/crazy-max/dagger-action)
|
||||
[](https://github.com/sponsors/crazy-max)
|
||||
[](https://www.paypal.me/crazyws)
|
||||
|
||||
## About
|
||||
|
||||
GitHub Action for [Dagger](https://dagger.io), a programmable deployment system.
|
||||
|
||||
___
|
||||
|
||||
* [Usage](#usage)
|
||||
* [Basic](#basic)
|
||||
* [Install Only](#install-only)
|
||||
* [Customizing](#customizing)
|
||||
* [inputs](#inputs)
|
||||
* [License](#license)
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic
|
||||
|
||||
```yaml
|
||||
name: dagger
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
-
|
||||
name: Dagger
|
||||
uses: crazy-max/dagger-action@v1
|
||||
with:
|
||||
age-key: ${{ secrets.DAGGER_AGE_KEY }}
|
||||
args: up
|
||||
```
|
||||
|
||||
### Install Only
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
-
|
||||
name: Install Dagger
|
||||
uses: crazy-max/dagger-action@v1
|
||||
with:
|
||||
install-only: true
|
||||
-
|
||||
name: Show Dagger version
|
||||
run: dagger version
|
||||
```
|
||||
|
||||
## Customizing
|
||||
|
||||
### inputs
|
||||
|
||||
Following inputs can be used as `step.with` keys
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|------------------|---------|--------------|------------------------------------------------------------------|
|
||||
| `version` | String | `latest` | Dagger version |
|
||||
| `age-key` | String | | Dagger private key |
|
||||
| `args` | String | | Arguments to pass to Dagger |
|
||||
| `workdir` | String | `.` | Working directory (below repository root) |
|
||||
| `install-only` | Bool | `false` | Just install Dagger |
|
||||
|
||||
## Development
|
||||
|
||||
```shell
|
||||
# format code and build javascript artifacts
|
||||
docker buildx bake pre-checkin
|
||||
|
||||
# validate all code has correctly formatted and built
|
||||
docker buildx bake validate
|
||||
|
||||
# run tests
|
||||
docker buildx bake test
|
||||
```
|
||||
|
||||
## How can I help?
|
||||
|
||||
All kinds of contributions are welcome :raised_hands:! The most basic way to show your support is to star :star2:
|
||||
the project, or to raise issues :speech_balloon: You can also support this project by
|
||||
[**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) :clap: or by making a
|
||||
[Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely! :rocket:
|
||||
|
||||
Thanks again for your support, it is much appreciated! :pray:
|
||||
|
||||
## License
|
||||
|
||||
MIT. See `LICENSE` for more details.
|
||||
16
__tests__/dagger.test.ts
Normal file
16
__tests__/dagger.test.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import fs = require('fs');
|
||||
import * as dagger from '../src/dagger';
|
||||
|
||||
describe('install', () => {
|
||||
it('acquires latest version of Dagger', async () => {
|
||||
const daggerBin = await dagger.install('latest');
|
||||
console.log(daggerBin);
|
||||
expect(fs.existsSync(daggerBin)).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('acquires 0.1.0-alpha.9 version of Dagger', async () => {
|
||||
const daggerBin = await dagger.install('0.1.0-alpha.9');
|
||||
console.log(daggerBin);
|
||||
expect(fs.existsSync(daggerBin)).toBe(true);
|
||||
}, 100000);
|
||||
});
|
||||
31
action.yml
Normal file
31
action.yml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
|
||||
name: 'Dagger Action'
|
||||
description: 'GitHub Action for Dagger, a programmable deployment system'
|
||||
author: 'crazy-max'
|
||||
branding:
|
||||
color: 'green'
|
||||
icon: 'package'
|
||||
|
||||
inputs:
|
||||
version:
|
||||
description: 'Dagger version'
|
||||
default: 'latest'
|
||||
required: false
|
||||
age-key:
|
||||
description: 'Dagger private key'
|
||||
required: false
|
||||
args:
|
||||
description: 'Arguments to pass to Dagger'
|
||||
required: false
|
||||
workdir:
|
||||
description: 'Working directory (below repository root)'
|
||||
default: '.'
|
||||
required: false
|
||||
install-only:
|
||||
description: 'Just install Dagger'
|
||||
default: 'false'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
5485
dist/index.js
generated
vendored
Normal file
5485
dist/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
67
docker-bake.hcl
Normal file
67
docker-bake.hcl
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
variable "NODE_VERSION" {
|
||||
default = "12"
|
||||
}
|
||||
|
||||
target "node-version" {
|
||||
args = {
|
||||
NODE_VERSION = NODE_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
group "default" {
|
||||
targets = ["build"]
|
||||
}
|
||||
|
||||
group "pre-checkin" {
|
||||
targets = ["vendor-update", "format", "build"]
|
||||
}
|
||||
|
||||
group "validate" {
|
||||
targets = ["format-validate", "build-validate", "vendor-validate"]
|
||||
}
|
||||
|
||||
target "build" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "build-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "build-validate" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "build-validate"
|
||||
}
|
||||
|
||||
target "format" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "format-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "format-validate" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "format-validate"
|
||||
}
|
||||
|
||||
target "vendor-update" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/vendor.Dockerfile"
|
||||
target = "update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "vendor-validate" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/vendor.Dockerfile"
|
||||
target = "validate"
|
||||
}
|
||||
|
||||
target "test" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/test.Dockerfile"
|
||||
target = "test-coverage"
|
||||
output = ["./coverage"]
|
||||
}
|
||||
42
hack/build.Dockerfile
Normal file
42
hack/build.Dockerfile
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# syntax=docker/dockerfile:1.2
|
||||
ARG NODE_VERSION
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache cpio findutils git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS deps
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install
|
||||
|
||||
FROM deps AS build
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run build && mkdir /out && cp -Rf dist /out/
|
||||
|
||||
FROM scratch AS build-update
|
||||
COPY --from=build /out /
|
||||
|
||||
FROM build AS build-validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
git add -A && cp -rf /out/* .; \
|
||||
if [ -n "$(git status --porcelain -- dist)" ]; then \
|
||||
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'; \
|
||||
git status --porcelain -- dist; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
FROM deps AS format
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run format \
|
||||
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out
|
||||
|
||||
FROM scratch AS format-update
|
||||
COPY --from=format /out /
|
||||
|
||||
FROM deps AS format-validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run format-check
|
||||
21
hack/test.Dockerfile
Normal file
21
hack/test.Dockerfile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# syntax=docker/dockerfile:1.2
|
||||
ARG NODE_VERSION
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS deps
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install
|
||||
|
||||
FROM deps AS test
|
||||
ENV RUNNER_TEMP=/tmp/github_runner
|
||||
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run test --coverageDirectory=/tmp/coverage
|
||||
|
||||
FROM scratch AS test-coverage
|
||||
COPY --from=test /tmp/coverage /
|
||||
23
hack/vendor.Dockerfile
Normal file
23
hack/vendor.Dockerfile
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# syntax=docker/dockerfile:1.2
|
||||
ARG NODE_VERSION
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS vendored
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install && mkdir /out && cp yarn.lock /out
|
||||
|
||||
FROM scratch AS update
|
||||
COPY --from=vendored /out /
|
||||
|
||||
FROM vendored AS validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
git add -A && cp -rf /out/* .; \
|
||||
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then \
|
||||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \
|
||||
git status --porcelain -- yarn.lock; \
|
||||
exit 1; \
|
||||
fi
|
||||
11
jest.config.js
Normal file
11
jest.config.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: false
|
||||
}
|
||||
40
package.json
Normal file
40
package.json
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"name": "dagger-action",
|
||||
"description": "GitHub Action for Dagger, a programmable deployment system",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc && ncc build",
|
||||
"test": "jest --coverage",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"pre-checkin": "yarn run format && yarn run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/crazy-max/dagger-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"dagger"
|
||||
],
|
||||
"author": "CrazyMax",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.3.0",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
"@actions/tool-cache": "^1.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.14",
|
||||
"@types/node": "^14.11.2",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
"jest": "^26.4.2",
|
||||
"jest-circus": "^26.4.2",
|
||||
"jest-runtime": "^26.4.2",
|
||||
"prettier": "^2.1.2",
|
||||
"ts-jest": "^26.4.1",
|
||||
"typescript": "^4.0.3",
|
||||
"typescript-formatter": "^7.2.2"
|
||||
}
|
||||
}
|
||||
19
src/context.ts
Normal file
19
src/context.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
export interface Inputs {
|
||||
version: string;
|
||||
ageKey: string;
|
||||
workdir: string;
|
||||
args: string;
|
||||
installOnly: boolean;
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
return {
|
||||
version: core.getInput('version') || 'latest',
|
||||
ageKey: core.getInput('age-key'),
|
||||
workdir: core.getInput('workdir') || '.',
|
||||
args: core.getInput('args'),
|
||||
installOnly: core.getBooleanInput('install-only')
|
||||
};
|
||||
}
|
||||
54
src/dagger.ts
Normal file
54
src/dagger.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as core from '@actions/core';
|
||||
import * as http from '@actions/http-client';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
const s3URL: string = 'https://dagger-io.s3.amazonaws.com/dagger';
|
||||
const osPlat: string = os.platform();
|
||||
const osArch: string = os.arch();
|
||||
|
||||
export async function install(version: string): Promise<string> {
|
||||
if (version == 'latest') {
|
||||
version = await getLatestVersion();
|
||||
}
|
||||
version = version.replace(/^v/, '');
|
||||
|
||||
const downloadUrl: string = util.format('%s/releases/%s/%s', s3URL, version, getFilename(version));
|
||||
core.info(`Downloading ${downloadUrl}`);
|
||||
const downloadPath: string = await tc.downloadTool(downloadUrl);
|
||||
core.debug(`Downloaded to ${downloadPath}`);
|
||||
|
||||
core.info('Extracting Dagger');
|
||||
let extPath: string;
|
||||
if (osPlat == 'win32') {
|
||||
extPath = await tc.extractZip(downloadPath);
|
||||
} else {
|
||||
extPath = await tc.extractTar(downloadPath);
|
||||
}
|
||||
core.debug(`Extracted to ${extPath}`);
|
||||
|
||||
const cachePath: string = await tc.cacheDir(extPath, 'dagger', version);
|
||||
core.debug(`Cached to ${cachePath}`);
|
||||
|
||||
const exePath: string = path.join(cachePath, osPlat == 'win32' ? 'dagger.exe' : 'dagger');
|
||||
core.debug(`Exe path is ${exePath}`);
|
||||
|
||||
return path.join(cachePath, osPlat == 'win32' ? 'dagger.exe' : 'dagger');
|
||||
}
|
||||
|
||||
async function getLatestVersion(): Promise<string> {
|
||||
const _http = new http.HttpClient('dagger-action');
|
||||
const res = await _http.get(`${s3URL}/latest_version`);
|
||||
return await res.readBody().then(body => {
|
||||
return body.trim();
|
||||
});
|
||||
}
|
||||
|
||||
const getFilename = (version: string): string => {
|
||||
const platform: string = osPlat == 'win32' ? 'windows' : osPlat;
|
||||
const arch: string = osArch == 'x64' ? 'amd64' : 'i386';
|
||||
const ext: string = osPlat == 'win32' ? '.zip' : '.tar.gz';
|
||||
return util.format('dagger_v%s_%s_%s%s', version, platform, arch, ext);
|
||||
};
|
||||
43
src/main.ts
Normal file
43
src/main.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import * as context from './context';
|
||||
import * as dagger from './dagger';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const inputs: context.Inputs = await context.getInputs();
|
||||
const daggerBin = await dagger.install(inputs.version);
|
||||
|
||||
if (inputs.installOnly) {
|
||||
const daggerDir = path.dirname(daggerBin);
|
||||
core.addPath(daggerDir);
|
||||
core.debug(`Added ${daggerDir} to PATH`);
|
||||
return;
|
||||
} else if (!inputs.args) {
|
||||
throw new Error('args input required');
|
||||
}
|
||||
|
||||
if (inputs.ageKey) {
|
||||
await core.group(`Import Dagger private key`, async () => {
|
||||
if (!fs.existsSync(path.join(os.homedir(), '.dagger'))) {
|
||||
fs.mkdirSync(path.join(os.homedir(), '.dagger'), {recursive: true});
|
||||
}
|
||||
await fs.writeFileSync(path.join(os.homedir(), '.dagger', 'keys.txt'), inputs.ageKey);
|
||||
});
|
||||
}
|
||||
|
||||
if (inputs.workdir && inputs.workdir !== '.') {
|
||||
core.info(`Using ${inputs.workdir} as working directory`);
|
||||
process.chdir(inputs.workdir);
|
||||
}
|
||||
|
||||
await exec.exec(`${daggerBin} ${inputs.args}`);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
2
test/.dagger/env/staging/.gitignore
vendored
Normal file
2
test/.dagger/env/staging/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# dagger state
|
||||
state/**
|
||||
17
test/.dagger/env/staging/plan/build.cue
vendored
Normal file
17
test/.dagger/env/staging/plan/build.cue
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"dagger.io/docker"
|
||||
"dagger.io/git"
|
||||
)
|
||||
|
||||
// Relay for fetching a git repository
|
||||
repo: git.#Repository & {
|
||||
remote: "https://github.com/crazy-max/docker-7zip"
|
||||
ref: "master"
|
||||
}
|
||||
|
||||
// Relay for building a docker image
|
||||
ctr: docker.#Build & {
|
||||
source: repo
|
||||
}
|
||||
21
test/.dagger/env/staging/values.yaml
vendored
Normal file
21
test/.dagger/env/staging/values.yaml
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
name: staging
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
azure_kv: []
|
||||
hc_vault: []
|
||||
age:
|
||||
- recipient: age1ldpnwlxnru3vpgnjvfny8g54jeweps6msv8hyckwcj3faju4g4psrwr37a
|
||||
enc: |
|
||||
-----BEGIN AGE ENCRYPTED FILE-----
|
||||
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA5OVN1b3g3V1l5NytJSDRj
|
||||
UTNPTDM1ei81cWtqdmh6RXljK1VhRWxnUG1FCjYrUzBlYmRkeGhQR1dERnJCVGtK
|
||||
WTlhMk8wNnVmbUo1cVlzcmJkV3lZR1EKLS0tIFgrZXBFWVNmMVA3b1N5VlZGQzBU
|
||||
UEdWcXQ2SW0xY01aanI1Yk1UTEZRdjgKfjibyF28JAblL9QtldQ3XHQ8ddHhVm9o
|
||||
Q0DY34QpP1Pa8RMd9qg3/WHIQcVcC328VX+JoiOB+CCLyjrX0pyPnw==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2021-05-30T04:47:50Z"
|
||||
mac: ENC[AES256_GCM,data:RVbdCv/3hPv3oSFCOLl7Xe3pdF9C/Uu/S7s8f35opKKK/qGX9xzFADMwjiirIpwU4BENhDFBD8jcmJj1LORd5x/jp5PY5yfq3ueppzqkZjplaP7bHxTT1/TaA2EkChBZb/Uvl18SkuZlwCnFl8s/y2mtS67WFFwdJK5wzEu0cbw=,iv:Lc3qnIYGJaIDy8hdTgC36Cun9uW7AealV4S/mln/d1c=,tag:nzCqihSut0jiAZ5uInz7MA==,type:str]
|
||||
pgp: []
|
||||
encrypted_suffix: secret
|
||||
version: 3.7.1
|
||||
3
test/keys.txt
Normal file
3
test/keys.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# created: 2021-05-30T06:47:50+02:00
|
||||
# public key: age1ldpnwlxnru3vpgnjvfny8g54jeweps6msv8hyckwcj3faju4g4psrwr37a
|
||||
AGE-SECRET-KEY-1Y6JFYMZQTSZFPNYCNQ449U80GKXRH3DRZ2PJ42EXAR6Y542QFAMQ3FQ24C
|
||||
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"newLine": "lf",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue