Switch to TypeScript Action (#3)
This commit is contained in:
parent
08d0501ff9
commit
95b7f65790
|
@ -1,6 +0,0 @@
|
|||
.git
|
||||
.github
|
||||
.res
|
||||
.editorconfig
|
||||
.gitignore
|
||||
action.yml
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/lib/** linguist-detectable=false
|
||||
/node_modules/** linguist-detectable=false
|
44
.github/workflows/docker.yml
vendored
44
.github/workflows/docker.yml
vendored
|
@ -1,44 +0,0 @@
|
|||
name: docker
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Set TAG_NAME
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: |
|
||||
echo "##[set-env name=TAG_NAME;]${GITHUB_REF#refs/tags/}"
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
-
|
||||
name: Docker Build
|
||||
run: |
|
||||
docker build \
|
||||
--build-arg "VERSION=${TAG_NAME}" \
|
||||
--tag "crazymax/ghaction-github-pages:${TAG_NAME:-snapshot}" \
|
||||
--tag "crazymax/ghaction-github-pages:latest" \
|
||||
--file Dockerfile .
|
||||
-
|
||||
name: Docker Login
|
||||
if: success() && startsWith(github.ref, 'refs/tags/v')
|
||||
env:
|
||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||
run: |
|
||||
echo "${DOCKER_PASSWORD}" | docker login --username crazymax --password-stdin
|
||||
-
|
||||
name: Docker Push
|
||||
if: success() && startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker push crazymax/ghaction-github-pages
|
23
.github/workflows/lint.yml
vendored
Normal file
23
.github/workflows/lint.yml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
name: lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- releases/*
|
||||
paths:
|
||||
- src/*
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
-
|
||||
name: Setup TS
|
||||
run: npm install tslint typescript -g
|
||||
-
|
||||
name: Lint check
|
||||
run: tslint './src/*.ts'
|
68
.github/workflows/release.yml
vendored
Normal file
68
.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- '**'
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
-
|
||||
name: Prepare
|
||||
id: prepare
|
||||
run: |
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
MINOR=${TAG%.*}
|
||||
MAJOR=${MINOR%.*}
|
||||
echo ::set-output name=tag_name::${TAG}
|
||||
echo ::set-output name=minor_tag::${MINOR}
|
||||
echo ::set-output name=major_tag::${MAJOR}
|
||||
echo ::set-output name=major_exists::$(git show-ref origin/releases/${MAJOR})
|
||||
-
|
||||
name: Set up Git
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
git config user.name "${GITHUB_ACTOR}"
|
||||
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
|
||||
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
|
||||
-
|
||||
name: Checkout releases/${{ steps.prepare.outputs.major_tag }} branch
|
||||
run: |
|
||||
git checkout -B releases/${{ steps.prepare.outputs.major_tag }}
|
||||
if [ -n "${{ steps.prepare.outputs.major_exists }}" ]; then
|
||||
git branch --set-upstream-to=origin/releases/${{ steps.prepare.outputs.major_tag }} releases/${{ steps.prepare.outputs.major_tag }}
|
||||
fi
|
||||
-
|
||||
name: NPM production deps
|
||||
run: |
|
||||
rm -rf node_modules
|
||||
sed -i '/node_modules/d' .gitignore
|
||||
npm install --production
|
||||
-
|
||||
name: Commit and push changes
|
||||
run: |
|
||||
git add --all
|
||||
git status --short -uno
|
||||
git commit -m 'Release ${{ steps.prepare.outputs.tag_name }}'
|
||||
git show --stat-count=10 HEAD
|
||||
git push -f origin releases/${{ steps.prepare.outputs.major_tag }}
|
||||
-
|
||||
name: Update ${{ steps.prepare.outputs.minor_tag }} tag
|
||||
run: |
|
||||
git push origin :refs/tags/${{ steps.prepare.outputs.minor_tag }}
|
||||
git tag -fa ${{ steps.prepare.outputs.minor_tag }} -m "Release ${{ steps.prepare.outputs.tag_name }}"
|
||||
git push origin ${{ steps.prepare.outputs.minor_tag }}
|
||||
-
|
||||
name: Update ${{ steps.prepare.outputs.major_tag }} tag
|
||||
run: |
|
||||
git push origin :refs/tags/${{ steps.prepare.outputs.major_tag }}
|
||||
git tag -fa ${{ steps.prepare.outputs.major_tag }} -m "Release ${{ steps.prepare.outputs.tag_name }}"
|
||||
git push origin ${{ steps.prepare.outputs.major_tag }}
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -30,7 +30,7 @@ jobs:
|
|||
-
|
||||
name: Deploy
|
||||
if: success()
|
||||
uses: crazy-max/ghaction-github-pages@master
|
||||
uses: ./
|
||||
with:
|
||||
target_branch: test
|
||||
build_dir: public
|
||||
|
|
94
.gitignore
vendored
94
.gitignore
vendored
|
@ -1,5 +1,97 @@
|
|||
/.dev
|
||||
|
||||
# Jetbrains
|
||||
/.idea
|
||||
/*.iml
|
||||
|
||||
/public
|
||||
# Ignore node_modules on active branch
|
||||
node_modules/
|
||||
|
||||
# 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": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
22
Dockerfile
22
Dockerfile
|
@ -1,22 +0,0 @@
|
|||
FROM alpine:latest
|
||||
|
||||
ARG VERSION
|
||||
|
||||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions#about-yaml-syntax-for-github-actions
|
||||
LABEL version="$VERSION" \
|
||||
repository="https://github.com/crazy-max/ghaction-github-pages" \
|
||||
homepage="https://github.com/crazy-max/ghaction-github-pages" \
|
||||
maintainer="CrazyMax" \
|
||||
"com.github.actions.name"="GitHub Pages" \
|
||||
"com.github.actions.description"="GitHub Action for deploying GitHub Pages" \
|
||||
"com.github.actions.icon"="upload-cloud" \
|
||||
"com.github.actions.color"="green"
|
||||
|
||||
RUN apk --update --no-cache add \
|
||||
curl \
|
||||
git \
|
||||
&& rm -rf /var/cache/apk/* /tmp/*
|
||||
|
||||
COPY LICENSE README.md /
|
||||
ADD entrypoint.sh /
|
||||
ENTRYPOINT [ "/entrypoint.sh" ]
|
12
README.md
12
README.md
|
@ -52,18 +52,6 @@ jobs:
|
|||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
Docker :whale: image is also provided and automatically updated within [Docker Hub](https://hub.docker.com/r/crazymax/ghaction-github-pages/tags) so you can directly use the following [Docker Hub action](https://help.github.com/en/articles/workflow-syntax-for-github-actions#example-using-a-docker-hub-action):
|
||||
|
||||
```yaml
|
||||
- name: Deploy
|
||||
if: success()
|
||||
uses: docker://crazymax/ghaction-github-pages
|
||||
env:
|
||||
INPUT_TARGET_BRANCH: gh-pages
|
||||
INPUT_BUILD_DIR: public
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
## 💅 Customizing
|
||||
|
||||
### inputs
|
||||
|
|
|
@ -13,11 +13,9 @@ inputs:
|
|||
description: 'Git branch where assets will be deployed'
|
||||
default: 'gh-pages'
|
||||
build_dir:
|
||||
description: 'Path to build directory to deploy'
|
||||
description: 'Build directory to deploy'
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
env:
|
||||
GITHUB_TOKEN: 'As provided by GitHub Actions'
|
||||
using: 'node12'
|
||||
main: 'lib/main.js'
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REPO=${INPUT_REPO:-$GITHUB_REPOSITORY}
|
||||
|
||||
if [ -z "$INPUT_TARGET_BRANCH" ]; then
|
||||
echo "⛔️ Target branch not defined"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$INPUT_BUILD_DIR" ]; then
|
||||
echo "⛔️ Build dir does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🏃 Deploying $INPUT_BUILD_DIR directory to $INPUT_TARGET_BRANCH branch"
|
||||
cd "$INPUT_BUILD_DIR"
|
||||
|
||||
git init
|
||||
git config user.name "${GITHUB_ACTOR}"
|
||||
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
|
||||
git add .
|
||||
git commit --allow-empty -m 'Deploy to GitHub pages'
|
||||
git push --force --quiet "https://${GITHUB_PAT:-"x-access-token:$GITHUB_TOKEN"}@github.com/${REPO}.git" "master:${INPUT_TARGET_BRANCH}"
|
||||
rm -rf .git
|
||||
|
||||
# Tried https://developer.github.com/v3/repos/pages/#request-a-page-build
|
||||
# but not working: { "message": "Resource not accessible by integration", "documentation_url": "https://developer.github.com/v3/repos/pages/#request-a-page-build" }
|
||||
# curl -XPOST -H"Authorization: token ${GITHUB_TOKEN}" -H"Accept: application/vnd.github.mister-fantastic-preview+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/pages/builds
|
||||
|
||||
cd "$GITHUB_WORKSPACE"
|
||||
echo "🎉 Content of $INPUT_BUILD_DIR has been deployed to GitHub Pages."
|
84
lib/main.js
Normal file
84
lib/main.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const child_process = __importStar(require("child_process"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const repo = core.getInput('repo') || process.env['GITHUB_REPOSITORY'] || '';
|
||||
const target_branch = core.getInput('target_branch') || 'gh-pages';
|
||||
const build_dir = core.getInput('build_dir', { required: true });
|
||||
const username = process.env['GITHUB_ACTOR'] || 'github-actions';
|
||||
if (!fs.existsSync(build_dir)) {
|
||||
core.setFailed('⛔️ Build dir does not exist');
|
||||
return;
|
||||
}
|
||||
core.info(`🏃 Deploying ${build_dir} directory to ${target_branch} branch on ${repo} repo`);
|
||||
process.chdir(build_dir);
|
||||
yield exec.exec('git', ['init']);
|
||||
yield exec.exec('git', ['config', 'user.name', username]);
|
||||
yield exec.exec('git', [
|
||||
'config',
|
||||
'user.email',
|
||||
`${username}@users.noreply.github.com`
|
||||
]);
|
||||
try {
|
||||
child_process.execSync('git status --porcelain').toString();
|
||||
}
|
||||
catch (err) {
|
||||
core.info('⚠️Nothing to deploy');
|
||||
return;
|
||||
}
|
||||
yield exec.exec('git', ['add', '.']);
|
||||
yield exec.exec('git', [
|
||||
'commit',
|
||||
'--allow-empty',
|
||||
'-m',
|
||||
'Deploy to GitHub pages'
|
||||
]);
|
||||
let gitURL = String('https://');
|
||||
if (process.env['GITHUB_PAT']) {
|
||||
gitURL.concat(process.env['GITHUB_PAT']);
|
||||
}
|
||||
else if (process.env['GITHUB_TOKEN']) {
|
||||
gitURL.concat('x-access-token:', process.env['GITHUB_TOKEN']);
|
||||
}
|
||||
else {
|
||||
core.setFailed('❌️ You have to provide a GITHUB_TOKEN or GITHUB_PAT');
|
||||
return;
|
||||
}
|
||||
gitURL.concat('@github.com/', repo, '.git');
|
||||
yield exec.exec('git', [
|
||||
'push',
|
||||
'--force',
|
||||
'--quiet',
|
||||
gitURL,
|
||||
`master:${target_branch}`
|
||||
]);
|
||||
process.chdir(process.env['GITHUB_WORKSPACE'] || '.');
|
||||
core.info(`🎉 Content of $INPUT_BUILD_DIR has been deployed to GitHub Pages.`);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
run();
|
111
package-lock.json
generated
Normal file
111
package-lock.json
generated
Normal file
|
@ -0,0 +1,111 @@
|
|||
{
|
||||
"name": "github-pages",
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.1.3.tgz",
|
||||
"integrity": "sha512-2BIib53Jh4Cfm+1XNuZYYGTeRo8yiWEAUMoliMh1qQGMaqTF4VUlhhcsBylTu4qWmUx45DrY0y0XskimAHSqhw=="
|
||||
},
|
||||
"@actions/exec": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.1.tgz",
|
||||
"integrity": "sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ=="
|
||||
},
|
||||
"@actions/io": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.1.tgz",
|
||||
"integrity": "sha512-rhq+tfZukbtaus7xyUtwKfuiCRXd1hWSfmJNEpFgBQJ4woqPEpsBw04awicjwz9tyG2/MVhAEMfVn664Cri5zA==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.7.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.12.tgz",
|
||||
"integrity": "sha512-KPYGmfD0/b1eXurQ59fXD1GBzhSQfz6/lKBxkaHX9dKTzjXbK68Zt7yGUxUsCS1jeTy/8aL+d9JEr+S54mpkWQ==",
|
||||
"dev": true
|
||||
},
|
||||
"commandpost": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/commandpost/-/commandpost-1.4.0.tgz",
|
||||
"integrity": "sha512-aE2Y4MTFJ870NuB/+2z1cXBhSBBzRydVVjzhFC4gtenEhpnj15yu0qptWGJsO9YGrcPZ3ezX8AWb1VA391MKpQ==",
|
||||
"dev": true
|
||||
},
|
||||
"editorconfig": {
|
||||
"version": "0.15.3",
|
||||
"resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz",
|
||||
"integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"commander": "^2.19.0",
|
||||
"lru-cache": "^4.1.5",
|
||||
"semver": "^5.6.0",
|
||||
"sigmund": "^1.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.20.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz",
|
||||
"integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "4.1.5",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz",
|
||||
"integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"pseudomap": "^1.0.2",
|
||||
"yallist": "^2.1.2"
|
||||
}
|
||||
},
|
||||
"prettier": {
|
||||
"version": "1.18.2",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
|
||||
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==",
|
||||
"dev": true
|
||||
},
|
||||
"pseudomap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=",
|
||||
"dev": true
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.7.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
|
||||
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"sigmund": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
|
||||
"integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=",
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz",
|
||||
"integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript-formatter": {
|
||||
"version": "7.2.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript-formatter/-/typescript-formatter-7.2.2.tgz",
|
||||
"integrity": "sha512-V7vfI9XArVhriOTYHPzMU2WUnm5IMdu9X/CPxs8mIMGxmTBFpDABlbkBka64PZJ9/xgQeRpK8KzzAG4MPzxBDQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"commandpost": "^1.0.0",
|
||||
"editorconfig": "^0.15.0"
|
||||
}
|
||||
},
|
||||
"yallist": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
|
||||
"integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
37
package.json
Normal file
37
package.json
Normal file
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"name": "github-pages",
|
||||
"description": "GitHub Action for deploying GitHub Pages",
|
||||
"main": "lib/main.js",
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"prune": "npm prune --production"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/crazy-max/ghaction-docker-buildx.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"github",
|
||||
"pages",
|
||||
"deploy"
|
||||
],
|
||||
"author": "CrazyMax",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.1.3",
|
||||
"@actions/exec": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/io": "^1.0.0",
|
||||
"@types/node": "^12.7.12",
|
||||
"prettier": "^1.17.1",
|
||||
"typescript": "^3.5.1",
|
||||
"typescript-formatter": "^7.2.2"
|
||||
}
|
||||
}
|
74
src/main.ts
Normal file
74
src/main.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
import * as child_process from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const repo =
|
||||
core.getInput('repo') || process.env['GITHUB_REPOSITORY'] || '';
|
||||
const target_branch = core.getInput('target_branch') || 'gh-pages';
|
||||
const build_dir = core.getInput('build_dir', {required: true});
|
||||
const username = process.env['GITHUB_ACTOR'] || 'github-actions';
|
||||
|
||||
if (!fs.existsSync(build_dir)) {
|
||||
core.setFailed('⛔️ Build dir does not exist');
|
||||
return;
|
||||
}
|
||||
|
||||
core.info(
|
||||
`🏃 Deploying ${build_dir} directory to ${target_branch} branch on ${repo} repo`
|
||||
);
|
||||
|
||||
process.chdir(build_dir);
|
||||
await exec.exec('git', ['init']);
|
||||
await exec.exec('git', ['config', 'user.name', username]);
|
||||
await exec.exec('git', [
|
||||
'config',
|
||||
'user.email',
|
||||
`${username}@users.noreply.github.com`
|
||||
]);
|
||||
|
||||
try {
|
||||
child_process.execSync('git status --porcelain').toString();
|
||||
} catch (err) {
|
||||
core.info('⚠️Nothing to deploy');
|
||||
return;
|
||||
}
|
||||
|
||||
await exec.exec('git', ['add', '.']);
|
||||
await exec.exec('git', [
|
||||
'commit',
|
||||
'--allow-empty',
|
||||
'-m',
|
||||
'Deploy to GitHub pages'
|
||||
]);
|
||||
|
||||
let gitURL = String('https://');
|
||||
if (process.env['GITHUB_PAT']) {
|
||||
gitURL.concat(process.env['GITHUB_PAT']);
|
||||
} else if (process.env['GITHUB_TOKEN']) {
|
||||
gitURL.concat('x-access-token:', process.env['GITHUB_TOKEN']);
|
||||
} else {
|
||||
core.setFailed('❌️ You have to provide a GITHUB_TOKEN or GITHUB_PAT');
|
||||
return;
|
||||
}
|
||||
gitURL.concat('@github.com/', repo, '.git');
|
||||
await exec.exec('git', [
|
||||
'push',
|
||||
'--force',
|
||||
'--quiet',
|
||||
gitURL,
|
||||
`master:${target_branch}`
|
||||
]);
|
||||
|
||||
process.chdir(process.env['GITHUB_WORKSPACE'] || '.');
|
||||
core.info(
|
||||
`🎉 Content of $INPUT_BUILD_DIR has been deployed to GitHub Pages.`
|
||||
);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"newLine": "lf",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user