Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling releases with versioned assets #370

Merged
merged 9 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/create-release-on-branch-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Create release on branch changes

on:
push:
branches-ignore:
# Dependabot does not have permissions to create releases
- 'dependabot/**'

jobs:
create_release_on_branch_changes:
name: "Create release on branch changes"
runs-on: ubuntu-latest
steps:
- name: Set release variables
id: resolve-release-vars
# Version 0.0.0-SHA is a schema that supports semantic versioning but
# should sink below proper versions.
# Output package.json to provide insight and help debugging
# Using branch names as tags allows other projects to track unreleased
# development.
run: |
RELEASE_BRANCH=$(echo ${GITHUB_REF#refs/heads/})
RELEASE_SHA=${{ github.sha }}
TAG_NAME=$(echo "branch-${RELEASE_BRANCH}")
echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> "$GITHUB_ENV"
echo "RELEASE_SHA=$RELEASE_SHA" >> "$GITHUB_ENV"
echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_ENV"
echo "NPM_VERSION=0.0.0-${RELEASE_SHA}" >> "$GITHUB_ENV"
echo "DIST_FILENAME=dist-$RELEASE_BRANCH.zip" >> "$GITHUB_ENV"

# Checkout the HEAD of the PR branch to get the latest commit message.
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get release description
run: |
echo "RELEASE_DESCRIPTION=$(git show -s --format=%s)" >> "$GITHUB_ENV"

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: "https://npm.pkg.github.com"
scope: "@${{ github.repository_owner }}"

- run: yarn install --frozen-lockfile

- name: Building
run: yarn css:build

- name: Bundling assets
run: ./bundle.sh
env:
VERSION: ${{ env.TAG_NAME }}-${{ env.RELEASE_SHA }}

- name: Rename assets
run: |
mv dist.zip $DIST_FILENAME

- name: Delete existing releases
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ env.TAG_NAME }}
github_token: ${{ secrets.GITHUB_TOKEN }}


- name: Create or update tag
uses: EndBug/[email protected]
with:
ref: ${{ env.TAG_NAME }}

- name: Create release
id: create-release
uses: softprops/action-gh-release@v1
with:
prerelease: true
target_commitish: ${{ env.RELEASE_SHA }}
tag_name: ${{ env.TAG_NAME }}
body: ${{ env.RELEASE_DESCRIPTION }}
files: ${{ env.DIST_FILENAME }}

- name: Adding summary
run: |
echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY

- name: Release NPM package
run: |
npm version ${{ env.NPM_VERSION }} --no-git-tag-version
echo ${{ env.TAG_NAME }}
cat package.json
npm publish --tag ${{ env.TAG_NAME }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Adding summary
run: |
echo "Npm package created 🚀. Version: ${{ env.NPM_VERSION }}" >> $GITHUB_STEP_SUMMARY
86 changes: 86 additions & 0 deletions .github/workflows/create-release-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Create release on tag

on:
push:
tags:
- "*"

jobs:
create_release_on_tag:
name: "Create release on tag"
runs-on: ubuntu-latest
steps:
- name: Set release variables
id: resolve-release-vars
run: |
RELEASE_NAME=${{ github.ref_name }}
RELEASE_SHA=${{ github.sha }}
echo "RELEASE_NAME=$RELEASE_NAME" >> "$GITHUB_ENV"
echo "RELEASE_SHA=$RELEASE_SHA" >> "$GITHUB_ENV"
echo "NPM_VERSION=${RELEASE_NAME}-${RELEASE_SHA}" >> "$GITHUB_ENV"
echo "DIST_FILENAME=dist-$RELEASE_NAME-$RELEASE_SHA.zip" >> "$GITHUB_ENV"

# Validate/parse version tag.
# If it is not a version tag it is ok, we just need to know it.
- uses: nowsprinting/check-version-format-action@v3
id: version

- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: "https://npm.pkg.github.com"
scope: "@${{ github.repository_owner }}"

- run: yarn install --frozen-lockfile

- name: Building
run: yarn css:build

- name: Bundling assets
run: ./bundle.sh
env:
VERSION: ${{ env.RELEASE_NAME }}-${{ env.RELEASE_SHA }}

- name: Rename assets
run: |
mv dist.zip ${{ env.DIST_FILENAME }}

- name: Create release
id: create-release
uses: softprops/action-gh-release@v1
with:
files: ${{ env.DIST_FILENAME }}

- name: Adding summary
run: |
echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY

- name: Modify package.json for local context
if: steps.version.outputs.is_valid == 'true'
# Values in package.json must match the current GitHub repository to
# publish to it.
run: |
npm exec -- json -I -f package.json -e "this.name='@$GITHUB_REPOSITORY'"
npm exec -- json -I -f package.json -e "this.repository='https://github.com/$GITHUB_REPOSITORY'"

- name: Release NPM package
if: steps.version.outputs.is_valid == 'true'
# The latest tag follows tagged versions to follow NPM conventions.
run: |
npm version ${{ env.NPM_VERSION }} --no-git-tag-version
cat package.json
npm publish --tag latest
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: If created add NPM created summary
if: steps.version.outputs.is_valid == 'true'
run: |
echo "Npm package created 🚀. Version: ${{ env.NPM_VERSION }}" >> $GITHUB_STEP_SUMMARY

- name: If created add NPM NOT created summary
if: steps.version.outputs.is_valid != 'true'
run: |
echo "No npm package created... Just so you know it." >> $GITHUB_STEP_SUMMARY

93 changes: 0 additions & 93 deletions .github/workflows/deployment.yml

This file was deleted.

5 changes: 5 additions & 0 deletions bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ cp -r ./public/icons ./build/icons
cp -r ./src/styles/css ./build/css
cp -r ./src/styles/fonts ./build/fonts
find ./src -name "*.js" -exec cp {} ./build/js \;

if [ -n "$VERSION" ]; then
echo $VERSION > ./build/version.txt
fi
spaceo marked this conversation as resolved.
Show resolved Hide resolved

zip -r dist.zip build/