Skip to content

Commit

Permalink
Add github workflow to publish and release package
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
adamgraham committed Nov 20, 2024
1 parent c482200 commit 5e0a380
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 1 deletion.
147 changes: 147 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Publish & Release

on: workflow_dispatch

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install dependencies
run: |
yarn config set network-timeout 300000
yarn install --prefer-offline
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Build
continue-on-error: false
run: yarn build
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
retention-days: 30

push:
name: Push
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Push distribution
run: |
MSG="$(printf "Publish distribution\n[skip ci]")"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add dist/index.min.* -f
git diff-index --quiet HEAD || git commit -m "$MSG" --no-verify --signoff
git push origin $BRANCH_NAME
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTION_ROLE }}
aws-region: us-east-2

- name: Sync files to S3 bucket
run: |
PACKAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \")
aws s3 sync dist s3://cdn.zigurous.com/forge-react@$PACKAGE_VERSION/dist --delete --exclude "*.ts"
publish:
name: Publish
needs: [push, deploy]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install dependencies
run: |
yarn config set network-timeout 300000
yarn install --prefer-offline
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to NPM
run: |
npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

release:
name: Release
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PACKAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \")
gh release create "$PACKAGE_VERSION" \
--target ${{ github.ref_name }} \
--title "$PACKAGE_VERSION" \
--latest
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Forge React

<a href="https://github.com/zigurous/forge-react/actions"><img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/zigurous/forge-react/build-push-deploy.yml" /></a>
<a href="https://github.com/zigurous/forge-react/actions"><img alt="GitHub Actions Workflow Status" src="https://img.shields.io/github/actions/workflow/status/zigurous/forge-react/publish-release.yml" /></a>
<a href="https://github.com/zigurous/forge-react/pkgs/npm/forge-react"><img alt="GitHub package.json version" src="https://img.shields.io/github/package-json/v/zigurous/forge-react" /></a>
<a href="https://github.com/zigurous/forge-react/blob/main/LICENSE"><img alt="GitHub License" src="https://img.shields.io/github/license/zigurous/forge-react" /></a>

Expand Down

0 comments on commit 5e0a380

Please sign in to comment.