Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to GitHub Actions (deploy master to gh-pages, commits to DO spaces) #87

Merged
merged 31 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
344fbce
I'm not sure if this will work, time to test
IAmJSD Sep 12, 2019
b87f4ca
Try this
IAmJSD Sep 12, 2019
33fd3a4
This is it oohhhhhhh
IAmJSD Sep 12, 2019
cd83d9f
u wot github
IAmJSD Sep 12, 2019
cf0823b
It'd just be deploy here
IAmJSD Sep 12, 2019
7d48914
That should be dist
IAmJSD Sep 12, 2019
c6c15d4
Test the action with a mock deployment
IAmJSD Sep 12, 2019
49f7d38
Right branch would help
IAmJSD Sep 12, 2019
f23899b
Are quotes not a thing?
IAmJSD Sep 12, 2019
130efd0
No it does need quotes, echo the ref
IAmJSD Sep 12, 2019
bf81dcc
Try this
IAmJSD Sep 12, 2019
78159ac
Make it deployment ready
IAmJSD Sep 12, 2019
092404a
This *should* work
IAmJSD Sep 12, 2019
78c2d6b
Hopefully this works
IAmJSD Sep 12, 2019
7c17f5b
Try this *I reset the bucket env var, this works locally*
IAmJSD Sep 12, 2019
37fc775
Set the ACL
IAmJSD Sep 12, 2019
96aa5d5
Lots of linting
IAmJSD Sep 12, 2019
be9573a
I don't know if this'll work
IAmJSD Sep 12, 2019
9f703b3
Fixes
IAmJSD Sep 12, 2019
da1f746
Try this
IAmJSD Sep 12, 2019
6700b70
Fix the comment code
IAmJSD Sep 12, 2019
5b30f4d
Test using the GH token
IAmJSD Sep 12, 2019
9ba3c41
Fix auth header, Add new line
IAmJSD Sep 12, 2019
320edf9
Add content type
IAmJSD Sep 13, 2019
6a0a2d0
Magic tidying fairy (∩ ͡° ͜ʖ ͡°)⊃━☆゚. * ・ 。゚,
MattIPv4 Sep 13, 2019
4d7259e
I'm not keeping this edit, I just want to test this
IAmJSD Sep 13, 2019
f3a3914
Hmmmm that worked, lets test moving that space
IAmJSD Sep 13, 2019
020a4cd
Try this (sorry for all the commits, I cannot recreate locally)
IAmJSD Sep 13, 2019
2cab7af
Merge branch 'master' into gh_actions
IAmJSD Sep 13, 2019
3e7c02e
try this
MattIPv4 Sep 13, 2019
8bcafbb
Merge branch 'master' into gh_actions
IAmJSD Sep 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm

- name: Use Node.js (.nvmrc)
uses: actions/setup-node@v1
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"

- name: npm ci, test, and build
run: |
npm ci
npm test
IAmJSD marked this conversation as resolved.
Show resolved Hide resolved
npm run build

- name: Deploy master to GitHub Pages
if: github.ref == 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@2.0.0
env:
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: master
BRANCH: gh-pages
FOLDER: dist

- uses: chrislennon/action-aws-cli@v1.1
IAmJSD marked this conversation as resolved.
Show resolved Hide resolved
IAmJSD marked this conversation as resolved.
Show resolved Hide resolved

- name: Deploy commit to DigitalOcean Spaces
run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read --content-encoding utf8
env:
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.SPACES_REGION }}

- name: Leave a comment
run: node ./build/createGithubComment.js
env:
COMMIT_SHA: ${{ github.sha }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPACES_REGION: ${{ secrets.SPACES_REGION }}
SPACES_BUCKET: ${{ secrets.SPACES_BUCKET }}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

7 changes: 5 additions & 2 deletions build/buildTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ const index = async (file, out) => {
const post = posthtml(plugins)

// Process
const result = await post.process(source)
const html = (await post.process(source)).html

// Remove comments before HTML
const result = html.replace(/^(<!--.+?-->[\w\n]*)*/gms, '')

// Export
fs.writeFileSync(Path.join(__dirname, '..', out), result.html, { flag: 'w+' })
fs.writeFileSync(Path.join(__dirname, '..', out), result, { flag: 'w+' })
console.log(`...build successfully, saved to ${out}`)
}

Expand Down
59 changes: 59 additions & 0 deletions build/createGithubComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2019 DigitalOcean

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

const fetch = require('node-fetch')
const path = require('path')
const { readdirSync } = require('fs')

const main = async () => {

const baseURL = `https://${process.env.SPACES_BUCKET}.${process.env.SPACES_REGION}.digitaloceanspaces.com/${process.env.COMMIT_SHA}`

const tools = readdirSync(path.join(__dirname, '..', 'dist'), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
.map(name => `[${name}](${baseURL}/${name}/index.html)`)

const comment = `This commit has been deployed to DigitalOcean Spaces for easy reviewing.

| ${tools.join(' | ')} |
|${(new Array(tools.length).fill('---')).join('|')}|`

const res = await fetch(
`https://api.github.com/repos/do-community/dns-tool/commits/${process.env.COMMIT_SHA}/comments`,
{
method: 'POST',
body: JSON.stringify({
body: comment,
}),
headers: {
'Content-Type': 'application/json',
Accept: 'application/vnd.github.v3+json',
Authorization: `Basic ${Buffer.from(`github-actions:${process.env.GITHUB_ACCESS_TOKEN}`).toString('base64')}`,
}
},
).catch(async e => {
console.log(await e.json())
process.exit(1)
})

if (!res.ok) {
console.log(await res.json())
process.exit(1)
}
}

main()
12 changes: 9 additions & 3 deletions build/fetchTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const main = async () => {
let rawHTML = await res.text()

// Parse
const { document } = (new JSDOM(rawHTML)).window
const dom = new JSDOM(rawHTML)
const { document } = dom.window
const nav = document.querySelector('nav.do_nav')

// Nuke top log in button
Expand Down Expand Up @@ -58,8 +59,13 @@ const main = async () => {
}
})

// Inject charset
const charset = document.createElement('meta')
charset.setAttribute('charset', 'utf8')
document.head.insertBefore(charset, document.head.firstChild)

// Convert back to raw
rawHTML = document.documentElement.innerHTML
rawHTML = dom.serialize()

// Inject title block
rawHTML = rawHTML.replace(/<title>(.+?)<\/title>/, '<title><block name="title"></block>$1</title>')
Expand All @@ -72,7 +78,7 @@ const main = async () => {
'<block name="content"></block><div class="clearfix"></div>')

// Inject last fetch comment
rawHTML = rawHTML.replace('<head>', `<head><!-- Last fetch from www.digitalocean.com @ ${(new Date()).toISOString()} -->`)
rawHTML = rawHTML.replace('<head>', `<!-- Last fetch from www.digitalocean.com @ ${(new Date()).toISOString()} -->\n<head>`)

// Export
fs.writeFileSync(`${__dirname}/base.html`, rawHTML, { flag: 'w+' })
Expand Down
2 changes: 1 addition & 1 deletion src/spf-explainer/templates/spf.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
<div v-if="!loading">
<h5 class="title is-5">
<span v-for="(_, key) in links" :key="key" :ref="key">
<a @click="goToIndex(key)" @mouseover="markActive(key)">{{ key }}&nbsp;</a>
<a @click="goToIndex(key)" @mouseover="markActive(key)">{{ key }} </a>
</span>
</h5>
<div v-for="part in parts" :key="part[0]">
Expand Down