WIP: Build & Release

This commit is contained in:
Michał Zieliński
2025-02-12 18:07:21 +01:00
parent c6736cd01d
commit c7188a34fa
3 changed files with 31 additions and 6 deletions

View File

@@ -6,20 +6,26 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@master uses: actions/setup-node@master
with: with:
node-version: 20 node-version: 20
- name: Install Angular CLI - name: Install Angular CLI
run: yarn global add @angular/cli run: yarn global add @angular/cli
- name: Configure ng to use yarn - name: Configure ng to use yarn
run: ng config --global cli.packageManager yarn run: ng config --global cli.packageManager yarn
- name: Yarn install - name: Yarn install
working-directory: Frontend working-directory: Frontend
run: yarn install run: yarn install
- name: Build Angular - name: Build Angular
working-directory: Frontend working-directory: Frontend
run: ng build --configuration=production run: ng build --configuration=production
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
@@ -30,23 +36,28 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup dotnet 9 - name: Setup dotnet 9
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
dotnet-version: 9.0.x dotnet-version: 9.0.x
- name: Install dependencies - name: Install dependencies
working-directory: WebAPI working-directory: WebAPI
run: dotnet restore run: dotnet restore
- name: Build - name: Build
working-directory: WebAPI working-directory: WebAPI
run: | run: |
dotnet build --configuration Release --no-restore dotnet build --configuration Release --no-restore
dotnet publish --configuration Release --framework net9.0 --runtime linux-x64 --self-contained false --output ./WebApiBuild dotnet publish --configuration Release --framework net9.0 --runtime linux-x64 --self-contained false --output ./WebApiBuild
- name: Clean up - name: Clean up
working-directory: WebAPI working-directory: WebAPI
run: | run: |
rm ./WebApiBuild/appsettings.Development.json rm ./WebApiBuild/appsettings.Development.json
rm ./WebApiBuild/client_secrets.Development.json rm ./WebApiBuild/client_secrets.Development.json
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:

View File

@@ -17,14 +17,11 @@ module.exports = async ({ github, context, core, jobId }) => {
let match; let match;
while (match = regex.exec(data)) { while (match = regex.exec(data)) {
const token = match[1].replace(/-/g, '_').toUpperCase(); const token = match[1].replace(/-/g, '_').toUpperCase();
console.log(token);
const value = getValue(token, jobId); const value = getValue(token, jobId);
console.log(value);
if (!value) { if (!value) {
core.setFailed(`Token ${token} not found`); core.setFailed(`Token ${token} not found`);
return false; return false;
} }
// replace all occurrences of the ${token} with the value in file
const result = data.replace(new RegExp(`#{${token}}`, 'g'), value); const result = data.replace(new RegExp(`#{${token}}`, 'g'), value);
require('fs').writeFileSync(file, result, 'utf8'); require('fs').writeFileSync(file, result, 'utf8');
} }

View File

@@ -17,9 +17,11 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Assign run ID if provided - name: Assign run ID if provided
if: ${{ github.event.inputs.job_id != '' }} if: ${{ github.event.inputs.job_id != '' }}
run: echo "job_id=${{ github.event.inputs.job_id }}" >> $GITHUB_ENV run: echo "job_id=${{ github.event.inputs.job_id }}" >> $GITHUB_ENV
- name: Get last build ID - name: Get last build ID
id: get-build-id id: get-build-id
if: ${{ github.event.inputs.job_id == '' }} if: ${{ github.event.inputs.job_id == '' }}
@@ -29,6 +31,7 @@ jobs:
const script = require('./.github/workflows/buildScripts/getLastBuildId.js'); const script = require('./.github/workflows/buildScripts/getLastBuildId.js');
const jobId = await script({github, context}); const jobId = await script({github, context});
core.setOutput("job_id", jobId); core.setOutput("job_id", jobId);
- name: Set job_id - name: Set job_id
if: ${{ github.event.inputs.job_id == '' }} if: ${{ github.event.inputs.job_id == '' }}
run: echo "job_id=${{ steps.get-build-id.outputs.job_id }}" >> $GITHUB_ENV run: echo "job_id=${{ steps.get-build-id.outputs.job_id }}" >> $GITHUB_ENV
@@ -38,20 +41,21 @@ jobs:
echo "Error: job_id is empty" echo "Error: job_id is empty"
exit 1 exit 1
fi fi
- name: Download frontend artifacts - name: Download frontend artifacts
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
script: | script: |
const script = require('./.github/workflows/buildScripts/downloadArtifacts.js'); const script = require('./.github/workflows/buildScripts/downloadArtifacts.js');
await script({github, context, core, jobId: ${{env.job_id}}, name: 'frontend'}); await script({github, context, core, jobId: ${{env.job_id}}, name: 'frontend'});
- name: Download backend artifacts - name: Download backend artifacts
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
script: | script: |
const script = require('./.github/workflows/buildScripts/downloadArtifacts.js'); const script = require('./.github/workflows/buildScripts/downloadArtifacts.js');
await script({github, context, core, jobId: ${{env.job_id}}, name: 'webapi'}); await script({github, context, core, jobId: ${{env.job_id}}, name: 'webapi'});
- name: List artifacts
run: ls -laR ./${{env.job_id}}
- name: Tokenize - name: Tokenize
uses: actions/github-script@v6 uses: actions/github-script@v6
env: env:
@@ -61,3 +65,16 @@ jobs:
script: | script: |
const script = require('./.github/workflows/buildScripts/replaceTokens.js'); const script = require('./.github/workflows/buildScripts/replaceTokens.js');
await script({github, context, core, jobId: ${{env.job_id}} }); await script({github, context, core, jobId: ${{env.job_id}} });
- name: Archive frontend artifacts
run: |
cd ${{env.job_id}}/frontend
zip -r ../morska-frontend.zip .
- name: Archive backend artifacts
run: |
cd ${{env.job_id}}/webapi
zip -r ../morska-webapi.zip .
- name: List artifacts
run: ls -la .