Merge pull request #5 from olzzon/develop #3
This file contains hidden or 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
####################################################################################################################### | |
# | |
# Node CI - Production | |
# | |
# The workflow ensures quality for the build, builds the project and publishes it to the configured destinations. | |
# There are the following destinations: | |
# | |
# [Github Release] | |
# The destination is only triggered if the secret 'RELEASE_TO_GITHUB' is set to a non-empty value. | |
# | |
# [NPM] | |
# The destination is only triggered if the secret 'NPM_TOKEN' is provided. | |
# | |
# [Docker Hub] | |
# The destination is only triggered if the secrets 'DOCKER_USERNAME' and 'DOCKER_PASSWORD' are | |
# provided. | |
# | |
####################################################################################################################### | |
name: Prod Node CI | |
env: | |
node-version: 18 | |
yarn-version: 4.1.0 | |
on: | |
push: | |
branches: | |
- "master" | |
- "main" | |
jobs: | |
cache-dependencies: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.bump-version.outputs.tag_version }} | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.node-version }} | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Set Yarn Version | |
run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
- name: Get Yarn cache directory | |
id: yarn-cache-dir | |
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | |
- name: Cache Yarn dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ steps.yarn-cache-dir.outputs.dir }} | |
.yarn/cache | |
.yarn/patches | |
.yarn/plugins | |
.yarn/releases | |
.yarn/sdks | |
.yarn/versions | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
# Regenerate the lockfile explicitly | |
- name: Update Lockfile | |
run: yarn install --mode=update-lockfile | |
# actual installation | |
- name: Install dependencies | |
run: yarn install --mode=skip-build | |
prebuild: | |
runs-on: ubuntu-latest | |
needs: cache-dependencies | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.node-version }} | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Set Yarn Version | |
run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
- name: Get Yarn cache directory | |
id: yarn-cache-dir | |
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | |
- name: Cache Yarn dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ steps.yarn-cache-dir.outputs.dir }} | |
.yarn/cache | |
.yarn/patches | |
.yarn/plugins | |
.yarn/releases | |
.yarn/sdks | |
.yarn/versions | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
# Regenerate the lockfile explicitly | |
- name: Update Lockfile | |
run: yarn install --mode=update-lockfile | |
# actual installation | |
- name: Install dependencies | |
run: yarn install --mode=skip-build | |
- name: Build | |
run: yarn build | |
test: | |
runs-on: ubuntu-latest | |
needs: cache-dependencies | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.node-version }} | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Set Yarn Version | |
run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
- uses: ./.github/actions/test | |
# validate-dependencies: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Access repository | |
# uses: actions/checkout@v4 | |
# - name: Setup Node.js | |
# uses: actions/setup-node@v4 | |
# with: | |
# node-version: ${{ env.node-version }} | |
# - name: Enable Corepack | |
# run: corepack enable | |
# - name: Set Yarn Version | |
# run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
# - uses: ./.github/actions/validate-dependencies | |
# Rest of the jobs remain the same but need Yarn setup... | |
bump-version: | |
runs-on: ubuntu-latest | |
needs: | |
- prebuild | |
- test | |
outputs: | |
tag_version: ${{ steps.tag_version.outputs.new_tag || steps.tag_version.outputs.previous_tag }} | |
version: ${{ steps.tag_version.outputs.new_version || steps.tag_version.outputs.previous_version }} | |
changelog: ${{ steps.tag_version.outputs.changelog }} | |
bumped: ${{ steps.tag_version.outputs.new_tag != '' }} | |
commit_sha: ${{ steps.commit_sha.outputs.commit_sha }} | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.node-version }} | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Set Yarn Version | |
run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
- name: Configure committer | |
run: | | |
git config user.name "${{ github.event.pusher.name }}" | |
git config user.email "${{ github.event.pusher.email }}" | |
- name: Bump version and push tag | |
id: tag_version | |
uses: mathieudutour/github-tag-action@v6.1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
default_bump: false | |
- name: Update package.json | |
if: steps.tag_version.outputs.new_tag != '' | |
uses: jossef/action-set-json-field@v2.1 | |
with: | |
file: package.json | |
field: version | |
value: ${{ steps.tag_version.outputs.new_version }} | |
- name: Update CHANGELOG.md | |
env: | |
changes: ${{ steps.tag_version.outputs.changelog }} | |
run: | | |
echo "$changes" > /tmp/tmp-changelog.md | |
[ -f CHANGELOG.md ] && cat CHANGELOG.md >> /tmp/tmp-changelog.md | |
mv /tmp/tmp-changelog.md CHANGELOG.md | |
- name: Commit and push changes to package.json and CHANGELOG.md | |
id: commit_sha | |
if: steps.tag_version.outputs.new_tag != '' | |
uses: EndBug/add-and-commit@v9 | |
with: | |
add: "['package.json', 'CHANGELOG.md']" | |
build: | |
runs-on: ubuntu-latest | |
needs: | |
- bump-version | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.bump-version.outputs.commit_sha }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.node-version }} | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Set Yarn Version | |
run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
- name: Get Yarn cache directory | |
id: yarn-cache-dir | |
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | |
- name: Cache Yarn dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ steps.yarn-cache-dir.outputs.dir }} | |
.yarn/cache | |
.yarn/patches | |
.yarn/plugins | |
.yarn/releases | |
.yarn/sdks | |
.yarn/versions | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
# Regenerate the lockfile explicitly | |
- name: Update Lockfile | |
run: yarn install --mode=update-lockfile | |
# actual installation | |
- name: Install dependencies | |
run: yarn install --mode=skip-build | |
- name: Build | |
run: yarn build | |
- name: Upload client build artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-client | |
path: client/dist | |
- name: Upload server build artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-server | |
path: server/dist | |
build-desktop: | |
runs-on: windows-latest | |
needs: | |
- bump-version | |
- build | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.bump-version.outputs.commit_sha }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.node-version }} | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Set Yarn Version | |
run: corepack prepare yarn@${{ env.yarn-version }} --activate | |
- name: Ensure commits from bump-version | |
run: git pull | |
- name: Get Yarn cache directory | |
id: yarn-cache-dir | |
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT | |
- name: Cache Yarn dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
${{ steps.yarn-cache-dir.outputs.dir }} | |
.yarn/cache | |
.yarn/patches | |
.yarn/plugins | |
.yarn/releases | |
.yarn/sdks | |
.yarn/versions | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-client | |
path: client/dist | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-server | |
path: server/dist | |
# Regenerate the lockfile explicitly | |
- name: Update Lockfile | |
run: yarn install --mode=update-lockfile | |
# actual installation | |
- name: Install dependencies | |
run: yarn install --mode=skip-build | |
- name: Build desktop | |
run: yarn build:desktop | |
- name: Upload desktop build artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-desktop | |
path: desktop/dist | |
check-github-release: | |
runs-on: ubuntu-latest | |
needs: build-desktop | |
outputs: | |
defined: ${{ steps.release.outputs.defined == 'true' }} | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Check if is set to release | |
id: release | |
uses: ./.github/actions/check-secret | |
with: | |
secret: ${{ secrets.RELEASE_TO_GITHUB }} | |
publish-github-release: | |
runs-on: ubuntu-latest | |
if: needs.bump-version.outputs.bumped == 'true' && needs.check-github-release.outputs.defined == 'true' | |
needs: | |
- bump-version | |
- check-github-release | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.bump-version.outputs.commit_sha }} | |
- name: Ensure commits from bump-version | |
run: git pull | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-desktop | |
path: desktop/dist | |
- name: Compress artifact to zip | |
uses: papeloto/action-zip@v1 | |
with: | |
files: dist | |
dest: "${{ github.event.repository.name }}-${{ needs.bump-version.outputs.version }}.zip" | |
- name: Create Github release with desktop exe | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: Release ${{ needs.bump-version.outputs.tag_version }} | |
tag_name: ${{ needs.bump-version.outputs.tag_version }} | |
body: ${{ needs.bump-version.outputs.changelog }} | |
files: | | |
desktop/dist/*.exe | |
desktop/dist/*.dmg | |
check-npm-token: | |
runs-on: ubuntu-latest | |
needs: build | |
outputs: | |
defined: ${{ steps.token.outputs.defined == 'true' }} | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Check if has username | |
id: token | |
uses: ./.github/actions/check-secret | |
with: | |
secret: ${{ secrets.NPM_TOKEN }} | |
publish-npm-package: | |
runs-on: ubuntu-latest | |
if: needs.check-npm-token.outputs.defined == 'true' | |
needs: | |
- bump-version | |
- check-npm-token | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Configure publisher | |
run: | | |
git config user.name "${{ github.event.pusher.name }}" | |
git config user.email "${{ github.event.pusher.email }}" | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }} | |
path: dist | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
registry-url: "https://registry.npmjs.org" | |
- name: Publish package | |
run: yarn publish --access=public --tag latest --new-version "${{ needs.bump-version.outputs.version }}" | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
check-docker-credentials: | |
runs-on: ubuntu-latest | |
needs: build | |
outputs: | |
defined: ${{ steps.username.outputs.defined == 'true' && steps.password.outputs.defined == 'true' }} | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- name: Check if has username | |
id: username | |
uses: ./.github/actions/check-secret | |
with: | |
secret: ${{ secrets.DOCKER_USERNAME }} | |
- name: Check if has password | |
id: password | |
uses: ./.github/actions/check-secret | |
with: | |
secret: ${{ secrets.DOCKER_PASSWORD }} | |
publish-docker-image: | |
runs-on: ubuntu-latest | |
if: needs.check-docker-credentials.outputs.defined == 'true' | |
needs: | |
- check-docker-credentials | |
steps: | |
- name: Access repository | |
uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-client | |
path: client/dist | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ${{ github.event.repository.name }}-server | |
path: server/dist | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: "olzzon/${{ github.event.repository.name }}" | |
tags: | | |
type=ref,event=branch | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |