Skip to content

Commit 518f1b5

Browse files
authored
Merge pull request #202 from scratchfoundation/gha-migration
This merge sunsets the CircleCI deployment workflow and replaces it with a GHA workflow.
2 parents 50b7ade + e66eace commit 518f1b5

File tree

3 files changed

+168
-86
lines changed

3 files changed

+168
-86
lines changed

.circleci/config.yml

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
version: 2.1
2-
orbs:
3-
node: circleci/node@5
1+
# version: 2.1
2+
# orbs:
3+
# node: circleci/node@5
44

5-
aliases:
6-
- &release-branches
7-
- master
8-
- develop
9-
- /^hotfix\//
5+
# aliases:
6+
# - &release-branches
7+
# - master
8+
# - develop
9+
# - /^hotfix\//
1010

11-
executors:
12-
default-executor:
13-
docker:
14-
- image: cimg/node:16.18.1 # Consider switching to LTS when scratch-audio supports that version
15-
working_directory: ~/project
16-
resource_class: medium
11+
# executors:
12+
# default-executor:
13+
# docker:
14+
# - image: cimg/node:16.18.1 # Consider switching to LTS when scratch-audio supports that version
15+
# working_directory: ~/project
16+
# resource_class: medium
1717

18-
commands:
19-
test:
20-
steps:
21-
- run:
22-
name: Test
23-
command: npm run test
24-
setup_deploy:
25-
steps:
26-
- run:
27-
name: Setup Deploy
28-
command: |
29-
export NODE_ENV=production
30-
export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
31-
echo "export NPM_TAG=latest" >> $BASH_ENV
32-
npm run build
33-
if [ -z "$BEFORE_DEPLOY_RAN" ]; then
34-
VPKG=$($(npm bin)/json -f package.json version)
35-
VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
36-
echo "export RELEASE_VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}" >> $BASH_ENV
37-
npm --no-git-tag-version version $VERSION
38-
if [[ "$CIRCLE_BRANCH" == hotfix/* ]]; then # double brackets are important for matching the wildcard
39-
echo "export NPM_TAG=hotfix" >> $BASH_ENV
40-
fi
41-
git config --global user.email "$(git log --pretty=format:"%ae" -n1)"
42-
git config --global user.name "$(git log --pretty=format:"%an" -n1)"
43-
echo "export BEFORE_DEPLOY_RAN=true" >> $BASH_ENV
44-
fi
45-
deploy:
46-
steps:
47-
- run:
48-
name: Deploy
49-
command: |
50-
echo "Deploying version $RELEASE_VERSION to $NPM_TAG"
51-
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
52-
npm publish --tag $NPM_TAG
53-
if npm info | grep -q $RELEASE_VERSION; then git tag $RELEASE_VERSION && git push https://${GH_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git $RELEASE_VERSION; fi
18+
# commands:
19+
# test:
20+
# steps:
21+
# - run:
22+
# name: Test
23+
# command: npm run test
24+
# setup_deploy:
25+
# steps:
26+
# - run:
27+
# name: Setup Deploy
28+
# command: |
29+
# export NODE_ENV=production
30+
# export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
31+
# echo "export NPM_TAG=latest" >> $BASH_ENV
32+
# npm run build
33+
# if [ -z "$BEFORE_DEPLOY_RAN" ]; then
34+
# VPKG=$($(npm bin)/json -f package.json version)
35+
# VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
36+
# echo "export RELEASE_VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}" >> $BASH_ENV
37+
# npm --no-git-tag-version version $VERSION
38+
# if [[ "$CIRCLE_BRANCH" == hotfix/* ]]; then # double brackets are important for matching the wildcard
39+
# echo "export NPM_TAG=hotfix" >> $BASH_ENV
40+
# fi
41+
# git config --global user.email "$(git log --pretty=format:"%ae" -n1)"
42+
# git config --global user.name "$(git log --pretty=format:"%an" -n1)"
43+
# echo "export BEFORE_DEPLOY_RAN=true" >> $BASH_ENV
44+
# fi
45+
# deploy:
46+
# steps:
47+
# - run:
48+
# name: Deploy
49+
# command: |
50+
# echo "Deploying version $RELEASE_VERSION to $NPM_TAG"
51+
# npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
52+
# npm publish --tag $NPM_TAG
53+
# if npm info | grep -q $RELEASE_VERSION; then git tag $RELEASE_VERSION && git push https://${GH_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git $RELEASE_VERSION; fi
5454

55-
jobs:
56-
build-and-test:
57-
executor: default-executor
58-
steps:
59-
- checkout
60-
- node/install-packages
61-
- test
62-
- persist_to_workspace:
63-
root: ~/project
64-
paths:
65-
- .
66-
deploy:
67-
executor: default-executor
68-
steps:
69-
- attach_workspace:
70-
at: ~/project
71-
- setup_deploy
72-
- deploy
55+
# jobs:
56+
# build-and-test:
57+
# executor: default-executor
58+
# steps:
59+
# - checkout
60+
# - node/install-packages
61+
# - test
62+
# - persist_to_workspace:
63+
# root: ~/project
64+
# paths:
65+
# - .
66+
# deploy:
67+
# executor: default-executor
68+
# steps:
69+
# - attach_workspace:
70+
# at: ~/project
71+
# - setup_deploy
72+
# - deploy
7373

74-
workflows:
75-
build-and-test-workflow:
76-
jobs:
77-
- build-and-test:
78-
filters:
79-
branches:
80-
ignore: *release-branches
81-
deploy-workflow:
82-
jobs:
83-
- build-and-test:
84-
filters:
85-
branches:
86-
only: *release-branches
87-
- deploy:
88-
context:
89-
- scratch-npm-creds
90-
requires:
91-
- build-and-test
74+
# workflows:
75+
# build-and-test-workflow:
76+
# jobs:
77+
# - build-and-test:
78+
# filters:
79+
# branches:
80+
# ignore: *release-branches
81+
# deploy-workflow:
82+
# jobs:
83+
# - build-and-test:
84+
# filters:
85+
# branches:
86+
# only: *release-branches
87+
# - deploy:
88+
# context:
89+
# - scratch-npm-creds
90+
# requires:
91+
# - build-and-test

.github/workflows/ci-cd.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#
2+
name: CI/CD
3+
4+
on:
5+
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
6+
pull_request: # Runs whenever a pull request is created or updated
7+
push: # Runs whenever a commit is pushed to the repository
8+
branches: [master, develop, hotfix/*]
9+
10+
concurrency:
11+
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: write # publish a GitHub release
16+
pages: write # deploy to GitHub Pages
17+
issues: write # comment on released issues
18+
pull-requests: write # comment on released pull requests
19+
20+
jobs:
21+
ci-cd:
22+
runs-on: ubuntu-latest
23+
env:
24+
TRIGGER_DEPLOY: ${{ startsWith(github.ref, 'refs/heads/master') || startsWith(github.ref, 'refs/heads/hotfix') || startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/beta') }}
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: wagoid/commitlint-github-action@v5
28+
if: github.event_name == 'pull_request'
29+
- uses: actions/setup-node@v3
30+
with:
31+
cache: "npm"
32+
node-version-file: ".nvmrc"
33+
34+
- name: Info
35+
run: |
36+
cat <<EOF
37+
Node version: $(node --version)
38+
NPM version: $(npm --version)
39+
GitHub ref: ${{ github.ref }}
40+
GitHub head ref: ${{ github.head_ref }}
41+
EOF
42+
43+
- name: Setup & Test
44+
run: |
45+
npm ci
46+
npm run test
47+
48+
- name: Generate release version
49+
run: |
50+
export NODE_ENV=production
51+
export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
52+
export VPKG=$($(npm bin)/json -f package.json version)
53+
export VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
54+
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
55+
if [[ "${GITHUB_REF##*/}" == hotfix/* ]]; then
56+
echo "NPM_TAG=hotfix" >> $GITHUB_ENV
57+
else
58+
echo "NPM_TAG=latest" >> $GITHUB_ENV
59+
fi
60+
61+
- name: Build
62+
run: |
63+
npm run build
64+
npm --no-git-tag-version version $RELEASE_VERSION
65+
66+
- name: Deploy to NPM (do a dry-run if not on master, develop, or hotfix/*)
67+
env:
68+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
69+
NPM_TAG: ${{ env.NPM_TAG }}
70+
run: |
71+
message=$([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "DRY RUN of" || echo "Deploying")
72+
echo "$message version $RELEASE_VERSION to $NPM_TAG"
73+
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
74+
npm publish --tag $NPM_TAG $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run")
75+
76+
- name: Check Release Version and Create Tag
77+
run: |
78+
if npm info | grep -q $RELEASE_VERSION; then
79+
git tag $RELEASE_VERSION
80+
git push origin $RELEASE_VERSION
81+
fi

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v16

0 commit comments

Comments
 (0)