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
- uses: crazy-max/ghaction-dump-context@v2
- name: Create Pages branch
uses: peterjgrainger/action-create-branch@v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: "gh-pages"
- name: Checkout Pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
# for debugging
- if: runner.debug == '1'
uses: mxschmitt/action-tmate@v3
# 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: printf "Placeholder homepage" > index.html
- name: Commit changes to Pages branch
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: gh-pages
commit_message: "Clear branch"
- name: Checkout main branch
uses: actions/checkout@v4
- name: Remove files user doesn't need
run: |
rm -rf \
CHANGELOG.md \
testbed.md \
.github/ISSUE_TEMPLATE \
.github/DISCUSSION_TEMPLATE \
.github/workflows/versioning.yaml \
.github/pull_request_template.md \
- name: Rename files
run: |
mv -f .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."
printf "USER=${user}" >> $GITHUB_ENV
printf "DESCRIPTION=${description}" >> $GITHUB_ENV
- name: Personalize readme for user
run: |
printf "
# ${{ 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@v7
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@v7
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@v5
with:
commit_message: "Setup repo"