Merge pull request #4 from JamilOmar/changeset-release/main #20
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
name: Release Packages Workflow | |
on: | |
push: | |
branches: | |
- main | |
env: | |
HUSKY: 0 | |
PROJECT_NAME: main | |
REPOSITORY: jamilomar | |
jobs: | |
packaging: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ github.workspace }} | |
strategy: | |
matrix: | |
node-version: [18] | |
npm-version: [8] | |
steps: | |
- uses: pnpm/[email protected] | |
with: | |
version: 9.7.0 | |
- uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
- name: Derive appropriate SHAs for base and head for `nx affected` commands | |
uses: nrwl/[email protected] | |
with: | |
main-branch-name: main | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/[email protected] | |
with: | |
node-version: ${{ matrix.node-version }} | |
always-auth: true | |
registry-url: https://registry.npmjs.org | |
- name: Print node/pnpm versions | |
id: versions | |
run: | | |
node_ver=$( node --version ) | |
pnpm_ver=$( pnpm --version || true ) | |
echo "Node: ${node_ver:1}" | |
echo "PNPM: $pnpm_ver" | |
echo "node_version=${node_ver:1}" >>$GITHUB_OUTPUT | |
- name: Use the node_modules cache if available [pnpm] | |
uses: actions/[email protected] | |
with: | |
path: ~/.pnpm-store | |
key: ${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}- | |
- name: Install dependencies | |
run: | | |
echo "Running pnpm install" | |
pnpm install --frozen-lockfile | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build Project | |
run: | | |
pnpm nx run-many --target=build --all --parallel 4 | |
- name: Modify Workspace File | |
run: sed -e "s|'libs\/|'dist/|" pnpm-workspace.yaml > pnpm-new.yaml && mv pnpm-new.yaml pnpm-workspace.yaml | |
- name: Create and Publish versions | |
id: changesets | |
uses: changesets/[email protected] | |
with: | |
commit: 'chore: update versions' | |
title: 'chore: update versions' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Release Changesets | |
id: release-changesets | |
if: steps.changesets.outputs.hasChangesets == 'false' | |
run: | | |
pnpm release:ci | |
echo "Modify Workspace File Back" | |
sed -e "s|'dist\/|'libs/|" pnpm-workspace.yaml > pnpm-new.yaml && mv pnpm-new.yaml pnpm-workspace.yaml | |
echo mainApiVersion="" >>$GITHUB_OUTPUT | |
echo mainAppVersion="" >>$GITHUB_OUTPUT | |
pnpm set-versions | |
if [ -f MAIN_API_VERSION ]; then | |
echo "mainApiVersion=$(cat MAIN_API_VERSION)" >>$GITHUB_OUTPUT | |
rm MAIN_API_VERSION | |
else | |
echo mainApiVersion="" >>$GITHUB_OUTPUT | |
fi | |
if [ -f MAIN_APP_VERSION ]; then | |
echo "mainAppVersion=$(cat MAIN_APP_VERSION)" >>$GITHUB_OUTPUT | |
rm MAIN_APP_VERSION | |
else | |
echo mainAppVersion="" >>$GITHUB_OUTPUT | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
mainApiVersion: ${{ steps.release-changesets.outputs.mainApiVersion }} | |
mainAppVersion: ${{ steps.release-changesets.outputs.mainAppVersion }} | |
publish-artifacts-for-api: | |
needs: [packaging] | |
if: needs.packaging.outputs.mainApiVersion != '' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ github.workspace }} | |
steps: | |
- name: Set Docker Login to ghcr.io | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
- name: Publish Artifacts for Api | |
run: | | |
echo "Using version: ${{ needs.packaging.outputs.mainApiVersion }}" | |
docker build -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-api -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-api:${{ needs.packaging.outputs.mainApiVersion }} --build-arg GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} -f ./apps/main/api/Dockerfile . | |
docker push ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-api --all-tags | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
mainApiVersion: ${{ needs.packaging.outputs.mainApiVersion }} | |
publish-artifacts-for-app: | |
needs: [packaging] | |
if: needs.packaging.outputs.mainAppVersion != '' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ github.workspace }} | |
steps: | |
- name: Set Docker Login to ghcr.io | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
- name: Publish Artifacts for App | |
run: | | |
echo "Using version: ${{ needs.packaging.outputs.mainAppVersion }}" | |
docker build -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-app -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-app:${{ needs.packaging.outputs.mainAppVersion }} --build-arg GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} -f ./apps/main/app/Dockerfile . | |
docker push ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-app --all-tags | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
mainAppVersion: ${{ needs.packaging.outputs.mainAppVersion }} |