-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to GitHub Actions (deploy master to gh-pages, commits to DO sp…
…aces) (#87) * I'm not sure if this will work, time to test * Try this * This is it oohhhhhhh * u wot github * It'd just be deploy here * That should be dist * Test the action with a mock deployment * Right branch would help * Are quotes not a thing? * No it does need quotes, echo the ref * Try this * Make it deployment ready * This *should* work * Hopefully this works * Try this *I reset the bucket env var, this works locally* * Set the ACL * Lots of linting * I don't know if this'll work * Fixes * Try this * Fix the comment code * Test using the GH token * Fix auth header, Add new line * Add content type * Magic tidying fairy (∩ ͡° ͜ʖ ͡°)⊃━☆゚. * ・ 。゚, * I'm not keeping this edit, I just want to test this * Hmmmm that worked, lets test moving that space * Try this (sorry for all the commits, I cannot recreate locally) * try this
- Loading branch information
Showing
6 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
|
||
- 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 }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters