Skip to content

Commit

Permalink
NEW Create action
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed May 31, 2022
1 parent 9809f12 commit 7b9c1be
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
push:
tags:
- '*.*.*'
jobs:
auto-tag:
name: Auto-tag
runs-on: ubuntu-latest
steps:
- name: Auto-tag
uses: silverstripe/gha-auto-tag@main
with:
ref: ${{ github.ref }}
sha: ${{ github.sha }}
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# gha-update-js
# GitHub Actions - Update JS

Update JS dependencies in core Silverstripe modules, create new bundles and create pull-requests

## Usage:

**.github/workflows/update-js.yml**
```yml
name: Update JS
on:
# Run on a schedule once per quarter
schedule:
- cron: '0 0 1 */3 *'
workflow_dispatch:
jobs:
update-js:
name: Update JS
runs-on: ubuntu-latest
steps:
- name: Update JS
uses: emteknetnz/gha-update-js@main
```
132 changes: 132 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Update JS
description: Updates JS dependencies in Silverstripe core modules
runs:
using: composite
steps:
- name: Checkout code
uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2

- name: Read .nvmrc
id: read-nvm
shell: bash
run: |
echo ::set-output name=version::$(cat .nvmrc)
- name: Setup node
uses: actions/setup-node@f1f314fca9dfce2769ece7d933488f076716723e #v1
with:
node-version: ${{ steps.read-nvm.outputs.version }}

- name: Install yarn
shell: bash
run: |
npm install --global yarn
- name: Install admin JS
if: github.event.repository.name != 'silverstripe-admin'
shell: bash
run: |
# Install admin js in sibling directory so shared components are available
DIR=$(pwd)
cd ..
git clone https://github.com/silverstripe/silverstripe-admin.git admin
cd admin
git checkout 1
yarn install
cd $DIR
# Use `yarn install` rather than `yarn upgrade` to prevent the following error:
# "error Outdated lockfile. Please run `yarn install` and try again."
- name: Update yarn.lock
shell: bash
run: |
if [ -f yarn.lock ]; then rm yarn.lock; fi
yarn install
- name: Read package.json
id: package-json
shell: bash
run: |
# Read package.json to see if lint and test are runnable scripts
LINT=0
TEST=0
if [ "$(jq .scripts.lint? package.json)" != "null" ]; then LINT=1; fi
if [ "$(jq .scripts.test? package.json)" != "null" ]; then TEST=1; fi
echo "::set-output name=lint::$LINT"
echo "::set-output name=test::$TEST"
echo "LINT is $LINT"
echo "TEST is $TEST"
# The following 3 steps make up `yarn build`
# Splitting apart to make it easier to see where any failures originate from
- name: Yarn lint
if: steps.package-json.outputs.lint == 1
shell: bash
run: |
yarn lint
- name: Yarn test
if: steps.package-json.outputs.test == 1
shell: bash
run: |
yarn test
- name: Build JS with webpack
# always run this and subsequent steps even if yarn.lint/yarn.test fails so that pull-request is
# created which will result in a red pull-request build so it's easy to see where things are at
if: always()
shell: bash
run: |
NODE_ENV=production node_modules/webpack/bin/webpack.js -p --bail --progress
- name: Remove any old pull-requests
if: always()
shell: bash
run: |
JSON=$(curl https://api.github.com/repos/${{ github.repository }}/pulls)
NUMBERS=$(echo $JSON | jq '.[] | select(.title=="DEP Update JS dependencies" and .user.login=="github-actions[bot]") | .number')
for NUMBER in $NUMBERS; do
curl -s \
-X PATCH https://api.github.com/repos/${{ github.repository }}/pulls/$NUMBER \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ github.token }}" \
-d @- << EOF
{
"state": "closed"
}
EOF
echo "Closed old pull-request $NUMBER"
done
- name: Remove any old branches
if: always()
shell: bash
run: |
JSON=$(curl https://api.github.com/repos/${{ github.repository }}/branches)
BRANCHES=$(echo $JSON | jq -r '.[] | .name | select(.|test("^pulls\/[0-9]\/update-js-[0-9]{10}$"))')
for BRANCH in $BRANCHES; do
if [[ "$BRANCH" =~ ^pulls/[0-9\.]+/update\-js\-[0-9]+$ ]]; then
git push origin --delete "$BRANCH"
echo "Deleted old branch $BRANCH"
fi
done
- name: Generate branch name
if: always()
id: generate-branch-name
shell: bash
run: |
# Convert refs/heads/mybranch to mybranch
CUT=$(echo ${{ github.ref }} | cut -c 12-)
# e.g. pulls/1/update-js-1647810133
BRANCH=pulls/$CUT/update-js-$(date +%s)
echo ::set-output name=branch::$BRANCH
- name: Git
if: always()
uses: emteknetnz/gha-pull-request@main
# TODO^ change this to silverstripe/gha-pull-request
with:
branch: ${{ steps.generate-branch-name.outputs.branch }}
title: DEP Update JS dependencies
description: Automated yarn upgrade and yarn build

0 comments on commit 7b9c1be

Please sign in to comment.