-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
193 additions
and
0 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,193 @@ | ||
name: Update | ||
on: | ||
issues: | ||
types: [opened] | ||
|
||
jobs: | ||
check_credentials: | ||
if: | | ||
(github.repository != 'j143/codelabs-template') && | ||
(github.event.issue.title == '[j143/codelabs-template] Automated Upgrade') | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: see payload | ||
run: | | ||
echo "FULL PAYLOAD:\n${PAYLOAD}\n" | ||
echo "PR_PAYLOAD PAYLOAD:\n${PR_PAYLOAD}" | ||
env: | ||
PAYLOAD: ${{ toJSON(github.event) }} | ||
PR_PAYLOAD: ${{ github.event.pull_request }} | ||
|
||
- name: Comment on issue if sufficient access does not exist | ||
if: | | ||
(github.event.issue.author_association != 'OWNER') && | ||
(github.event.issue.author_association != 'COLLABORATOR') && | ||
(github.event.issue.author_association != 'MEMBER') | ||
uses: actions/github-script@6.1.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
var permission_level = process.env.permission_level; | ||
var url = 'https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/permission-levels-for-a-user-account-repository#collaborator-access-on-a-repository-owned-by-a-user-account' | ||
var msg = `You must have the [permission level](${url}) of either an **OWNER**, **COLLABORATOR** or **MEMBER** to instantiate an upgrade request. Your permission level is ${permission_level}` | ||
github.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: msg | ||
}) | ||
github.issues.update({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
state: 'closed' | ||
}) | ||
throw msg; | ||
env: | ||
permission_level: ${{ github.event.issue.author_association }} | ||
|
||
upgrade: | ||
needs: [check_credentials] | ||
if: | | ||
(github.repository != 'fastai/fastpages') && | ||
(github.event.issue.title == '[fastpages] Automated Upgrade') && | ||
(github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'COLLABORATOR' || github.event.issue.author_association == 'MEMBER') | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
|
||
- name: copy this repo's contents | ||
uses: actions/checkout@v2 | ||
with: | ||
path: 'current_files' | ||
persist-credentials: false | ||
|
||
- name: copy new files | ||
if: steps.check_version.outputs.vbump == 'true' | ||
run: | | ||
cd new_files | ||
rm -rf _posts _notebooks _word images | ||
rm *.md CNAME action.yml _config.yml index.html LICENSE | ||
rm _pages/*.md | ||
rm .github/workflows/chatops.yaml | ||
rm .github/workflows/docker.yaml | ||
rm .github/ISSUE_TEMPLATE/bug.md .github/ISSUE_TEMPLATE/feature_request.md | ||
# | ||
for file in $(ls | egrep -v "(assets|_sass)"); do | ||
if [[ -f "$file" ]] || [[ -d "$file" ]] | ||
then | ||
echo "copying $file"; | ||
cp -r $file ../current_files; | ||
fi | ||
done | ||
# copy custom-variables.scss if doesn't exist | ||
if [ ! -f "../current_files/_sass/minima/custom-variables.scss" ]; then | ||
cp _sass/minima/custom-variables.scss ../current_files/_sass/minima/ | ||
fi | ||
# copy select files in assets and _sass | ||
cp -r assets/js ../current_files/assets | ||
cp -r assets/badges ../current_files/assets | ||
cp _sass/minima/fastpages-styles.scss ../current_files/_sass/minima/ | ||
cp _sass/minima/fastpages-dracula-highlight.scss ../current_files/_sass/minima/ | ||
# copy action workflows | ||
cp -r .github ../current_files | ||
# install dependencies | ||
pip3 install pyyaml | ||
- uses: webfactory/ssh-agent@v0.4.1 | ||
if: steps.check_version.outputs.vbump == 'true' | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_DEPLOY_KEY }} | ||
|
||
- name: push changes to branch | ||
if: steps.check_version.outputs.vbump == 'true' | ||
run: | | ||
# commit changes | ||
cd current_files | ||
git config --global user.email "${GH_USERNAME}@users.noreply.github.com" | ||
git config --global user.name "${GH_USERNAME}" | ||
git remote remove origin | ||
git remote add origin "git@github.com:${GITHUB_REPOSITORY}.git" | ||
git add _action_files/settings.ini | ||
git checkout -b automated-upgrade | ||
git add -A | ||
git commit -m'upgrade template' | ||
git push -f --set-upstream origin automated-upgrade master | ||
env: | ||
GH_USERNAME: ${{ github.event.issue.user.login }} | ||
|
||
- name: Open a PR | ||
if: steps.check_version.outputs.vbump == 'true' | ||
id: pr | ||
uses: actions/github-script@0.6.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
var fs = require('fs'); | ||
var contents = fs.readFileSync('upgrade_pr.md', 'utf8'); | ||
github.pulls.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
title: '[fastpages] Update repo with changes from fastpages', | ||
head: 'fastpages-automated-upgrade', | ||
base: 'master', | ||
body: `${contents}` | ||
}) | ||
.then(result => console.log(`::set-output name=pr_num::${result.data.number}`)) | ||
|
||
- name: Comment on issue | ||
if: steps.check_version.outputs.vbump == 'true' | ||
uses: actions/github-script@0.6.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
var pr_num = process.env.PR_NUM; | ||
var repo = process.env.REPO | ||
github.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Opened PR https://github.com/${repo}/pull/${pr_num} to assist with update.` | ||
}) | ||
env: | ||
PR_NUM: ${{ steps.pr.outputs.pr_num }} | ||
REPO: ${{ github.repository }} | ||
|
||
- name: Comment on issue if version has not changed | ||
if: steps.check_version.outputs.vbump == 'false' | ||
uses: actions/github-script@6.1.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
github.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Your version of fastpages is up to date. There is nothing to change.` | ||
}) | ||
- name: Close Issue | ||
if: always() | ||
uses: actions/github-script@6.1.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
github.issues.update({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
state: 'closed' | ||
}) |