⬆️ Upgrade dependencies #194
Workflow file for this run
This file contains 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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
name: 🔄 CI/CD | |
on: | |
push: | |
branches: ["main", "beta", "*.*.*"] | |
pull_request: | |
branches: ["main", "beta", "*.*.*"] | |
workflow_dispatch: # allow manual trigger | |
# Used by the GitHub merge queue feature. | |
# Documentation: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue | |
merge_group: | |
env: | |
NAMESPACE_NAME: "freegamescatcher" | |
IMAGE_NAME: "freegamescatcher-core" | |
jobs: | |
build: | |
name: ⚙️ Build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x, current] | |
steps: | |
- name: 📥 Checkout repository | |
uses: actions/checkout@v4 | |
- name: 🌐 Use Node.js [${{ matrix.node-version }}] | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: 🗂 Cache "node_modules" | |
uses: actions/cache@v3 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: "**/node_modules" | |
key: ${{ runner.arch }}-${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.arch }}-${{ runner.os }}-yarn- | |
- name: 📦 Install dependencies | |
if: steps.yarn-cache.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: ⚙️ Build application | |
run: yarn run build | |
- name: 🗃 List the state of node modules | |
if: steps.yarn-cache.outputs.cache-hit != 'true' | |
continue-on-error: true | |
run: yarn list | |
test-unit: | |
name: 🧪 Unit tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: 📥 Checkout repository | |
uses: actions/checkout@v4 | |
- name: 🌐 Use Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
- name: 🗂 Cache "node_modules" | |
uses: actions/cache@v3 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: "**/node_modules" | |
key: ${{ runner.arch }}-${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.arch }}-${{ runner.os }}-yarn- | |
- name: 📦 Install dependencies | |
if: steps.yarn-cache.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: 🧪 Run unit tests | |
run: yarn run test:unit | |
- name: 🗃 List the state of node modules | |
if: steps.yarn-cache.outputs.cache-hit != 'true' | |
continue-on-error: true | |
run: yarn list | |
release: | |
name: 🔖 Release | |
runs-on: ubuntu-latest | |
needs: [build, test-unit] | |
# Skip this job if the event is a merge_group and if the actor is dependabot. | |
if: github.event_name != 'merge_group' && github.actor != 'dependabot[bot]' | |
steps: | |
- name: 📥 Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
# used by semantic-release to bypass the branch protection rules | |
token: ${{ secrets.GH_TOKEN }} | |
- name: 🌐 Use Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
- name: 🗂 Cache "node_modules" | |
uses: actions/cache@v3 | |
with: | |
path: "**/node_modules" | |
key: ${{ runner.arch }}-${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.arch }}-${{ runner.os }}-yarn- | |
- name: 🔖 Release application | |
run: yarn run release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }} # optional, needed to publish packages on npm | |
id: version # save the version to use in an other step/job | |
outputs: | |
version: ${{ steps.version.outputs.nextVersion }} | |
push: | |
name: 🐳 Build and push image | |
runs-on: ubuntu-latest | |
needs: release | |
steps: | |
- name: 📥 Checkout repository | |
uses: actions/checkout@v4 | |
- name: 🌳 Extract branch name | |
id: extract-branch-name | |
uses: size-up/actions/.github/actions/extract-branch-name@v1 | |
- name: ⚙️ Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: 🛠 Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: 📲 Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: 🐳 Build and push image [${{ steps.extract-branch-name.outputs.branch-name-extracted }}] | |
uses: docker/build-push-action@v5 | |
with: | |
context: . # https://github.com/marketplace/actions/build-and-push-docker-images#git-context | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.extract-branch-name.outputs.branch-name-extracted }} | |
build-args: | | |
NODE_ENV=pre-production | |
VERSION=${{ steps.extract-branch-name.outputs.branch-name-extracted }} | |
- name: 🐳 Build and push image [${{ needs.release.outputs.version }}] | |
uses: docker/build-push-action@v5 | |
if: needs.release.outputs.version # deploy only if there is a new published version | |
with: | |
context: . # https://github.com/marketplace/actions/build-and-push-docker-images#git-context | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.version }} | |
build-args: | | |
VERSION=${{ needs.release.outputs.version }} | |
outputs: | |
branch_name: ${{ steps.extract-branch-name.outputs.branch-name-extracted }} | |
deploy-prep: | |
name: 🚀 Deploy prep. [${{ needs.push.outputs.branch_name }}] | |
runs-on: ubuntu-latest | |
needs: [release, push] | |
environment: pre-production # refer to https://github.com/size-up/freegamescatcher-core/settings/environments | |
concurrency: pre-production # refer to https://docs.github.com/en/actions/using-jobs/using-concurrency | |
steps: | |
- name: ⚙️ Set up kubectl | |
uses: tale/kubectl-action@v1 | |
with: | |
base64-kube-config: ${{ secrets.OCI_KUBE_CONFIG }} | |
- name: 🔊 Display deployment image before update | |
run: kubectl get deployments -n ${{ env.NAMESPACE_NAME }} ${{ env.IMAGE_NAME }}-prep -o=wide | |
- name: 🚀 Set image [${{ needs.push.outputs.branch_name }}] to pre-production | |
id: image_updated | |
run: | | |
echo value=$(kubectl set image -n ${{ env.NAMESPACE_NAME }} deployment/${{ env.IMAGE_NAME }}-prep ${{ env.IMAGE_NAME }}-prep=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ needs.push.outputs.branch_name }}) >> $GITHUB_OUTPUT | |
- name: 🔊 Display "set_image" step output | |
run: echo ${{ steps.image_updated.outputs.value }} | |
# Rollout the deployment only if the image hasn't been updated, to avoid unnecessary restarts. | |
- name: 🚀 Rollout pre-production deployment | |
id: rollout | |
if: steps.image_updated.outputs.value == '' # rollout only if the image hasn't been updated | |
run: echo value=$(kubectl rollout -n ${{ env.NAMESPACE_NAME }} restart deployment ${{ env.IMAGE_NAME }}-prep) >> $GITHUB_OUTPUT | |
- name: 🔊 Display "rollout" step output | |
if: steps.rollout.outputs.value | |
run: echo ${{ steps.rollout.outputs.value }} | |
- name: 🔊 Display deployment image after update | |
run: kubectl get deployments -n ${{ env.NAMESPACE_NAME }} ${{ env.IMAGE_NAME }}-prep -o=wide | |
deploy-prod: | |
name: 🚀 Deploy prod. [v${{ needs.release.outputs.version }}] | |
runs-on: ubuntu-latest | |
needs: [release, push] | |
# Deploy to production job is only available if the event is not a pull request, and | |
# if there is a new published versionas "1.0.0" and or "1.0.0-beta.1". | |
if: github.event_name != 'pull_request' && needs.release.outputs.version | |
environment: production # refer to https://github.com/size-up/freegamescatcher-core/settings/environments | |
concurrency: production # refer to https://docs.github.com/en/actions/using-jobs/using-concurrency | |
steps: | |
- name: ⚙️ Set up kubectl | |
uses: tale/kubectl-action@v1 | |
with: | |
base64-kube-config: ${{ secrets.OCI_KUBE_CONFIG }} | |
- name: 🚀 Deploy to production [v${{ needs.release.outputs.version }}] | |
run: kubectl set image -n ${{ env.NAMESPACE_NAME }} deployment/${{ env.IMAGE_NAME }}-prod ${{ env.IMAGE_NAME }}-prod=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.version }} |