Skip to content

first time setup of repo #1

first time setup of repo

first time setup of repo #1

name: first-time-setup
run-name: first time setup of repo
on:
# run if user manually requests it
workflow_dispatch:
permissions:
contents: write
jobs:
first-time-setup:
runs-on: ubuntu-latest
steps:
# for debugging
- name: Print contexts
uses: crazy-max/ghaction-dump-context@v1
- name: Create Pages branch
uses: peterjgrainger/action-create-branch@v2.4.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "gh-pages"
- name: Checkout Pages branch
uses: actions/checkout@v3
with:
ref: gh-pages
# clean slate, as if starting from orphan branch
- name: Clear Pages branch
run: rm -rf * .github .docker .gitignore
# prevent GitHub from running Jekyll a second time after build
- name: Make .nojekyll file
run: touch .nojekyll
- name: Make placeholder homepage
run: echo "Placeholder homepage" > index.html
- name: Commit changes to Pages branch
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: gh-pages
commit_message: "Clear branch"
- name: Checkout main branch
uses: actions/checkout@v3
- name: Remove files user doesn't need
run: |
rm -rf \
CHANGELOG.md \
testbed.md \
.github/ISSUE_TEMPLATE \
.github/workflows/versioning.yaml \
.github/pull_request_template.md \
- name: Rename files
run: |
mv .github/user_pull_request_template.md .github/pull_request_template.md
- name: Set vars for personalization
run: |
user="${{ github.repository_owner }}"
description="An engaging 1-3 sentence description of your lab."
echo "USER=${user}" >> $GITHUB_ENV
echo "DESCRIPTION=${description}" >> $GITHUB_ENV
- name: Personalize readme for user
run: |
echo "
# ${{ env.USER }}'s Website
Visit **[website url](#)** 🚀
_Built with [Lab Website Template](https://greene-lab.gitbook.io/lab-website-template-docs)_
" > README.md
- name: Personalize Jekyll config for user
uses: actions/github-script@v6
with:
script: |
const { readFileSync, writeFileSync } = require("fs");
const file = "_config.yaml";
const contents = readFileSync(file)
.toString()
.replace(/(^title: ).*$/m, "$1${{ env.USER }}")
.replace(/(^subtitle: ).*$/m, "$1")
.replace(/(^description: ).*$/m, "$1${{ env.DESCRIPTION }}")
.replace(/(^ email: ).*$/m, "$1contact@${{ env.USER }}.com")
.replace(/(^ github: ).*$/m, "$1${{ env.USER }}")
.replace(/(^ twitter: ).*$/m, "$1${{ env.USER }}")
.replace(/(^ youtube: ).*$/m, "$1${{ env.USER }}");
writeFileSync(file, contents);
- name: Personalize homepage for user
uses: actions/github-script@v6
with:
script: |
const { readFileSync, writeFileSync } = require("fs");
const file = "index.md";
let contents = readFileSync(file).toString();
const find = /\# Lab Website Template[\s\S]+({% include section\.html)/;
const replace = `# ${{ env.USER }}'s Website\n\n${{ env.DESCRIPTION }}\n\n$1`;
contents = contents.replace(find, replace);
writeFileSync(file, contents);
- name: Commit changed files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Setup repo"