WIP: Build & Release
This commit is contained in:
26
.github/workflows/buildScripts/downloadArtifacts.js
vendored
Normal file
26
.github/workflows/buildScripts/downloadArtifacts.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
module.exports = async ({ github, context, core, jobId, name }) => {
|
||||||
|
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
run_id: jobId,
|
||||||
|
});
|
||||||
|
if (artifacts.data.total_count === 0) {
|
||||||
|
core.setFailed("No artifacts found for jobID: " + jobId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const artifact = artifacts.data.artifacts.find(
|
||||||
|
(artifact) => artifact.name === name
|
||||||
|
);
|
||||||
|
if (!artifact) {
|
||||||
|
core.setFailed(`${name} not found in artifacts`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const response = await github.rest.actions.downloadArtifact({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
artifact_id: artifact.id,
|
||||||
|
archive_format: "zip"
|
||||||
|
});
|
||||||
|
require('fs').writeFileSync(`${name}.zip`, Buffer.from(response.data));
|
||||||
|
require('child_process').execSync(`unzip -o ${name}.zip -d ./${jobId}`);
|
||||||
|
};
|
||||||
11
.github/workflows/buildScripts/getLastBuildId.js
vendored
Normal file
11
.github/workflows/buildScripts/getLastBuildId.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
module.exports = async ({ github, context }) => {
|
||||||
|
const { data: runs } = await github.rest.actions.listWorkflowRuns({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
workflow_id: "build.yml",
|
||||||
|
branch: "main",
|
||||||
|
status: "success",
|
||||||
|
per_page: 1,
|
||||||
|
});
|
||||||
|
return runs.workflow_runs[0].id;
|
||||||
|
};
|
||||||
3
.github/workflows/buildScripts/replaceTokens.js
vendored
Normal file
3
.github/workflows/buildScripts/replaceTokens.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = async ({ github, context, core, jobId }) => {
|
||||||
|
|
||||||
|
}
|
||||||
49
.github/workflows/release-morska.yml
vendored
Normal file
49
.github/workflows/release-morska.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
name: Morska Release
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
job_id:
|
||||||
|
description: 'Job ID of the build to release'
|
||||||
|
required: false
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: Morska
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Assign run ID if provided
|
||||||
|
if: ${{ github.event.inputs.job_id != '' }}
|
||||||
|
run: echo "job_id=${{ github.event.inputs.job_id }}" >> $GITHUB_ENV
|
||||||
|
- name: Get last build ID
|
||||||
|
id: get-build-id
|
||||||
|
if: ${{ github.event.inputs.job_id == '' }}
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const script = require('./.github/workflows/buildScripts/getLastBuildId.js');
|
||||||
|
const jobId = await script({github, context});
|
||||||
|
core.setOutput("job_id", jobId);
|
||||||
|
- name: Set job_id
|
||||||
|
if: ${{ github.event.inputs.job_id == '' }}
|
||||||
|
run: echo "job_id=${{ steps.get-build-id.outputs.job_id }}" >> $GITHUB_ENV
|
||||||
|
- name: Download frontend artifacts
|
||||||
|
if: ${{ github.event.inputs.job_id == '' }}
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const script = require('./.github/workflows/buildScripts/downloadArtifacts.js');
|
||||||
|
await script({github, context, core, jobId: ${{env.job_id}}, name: 'frontend'});
|
||||||
|
- name: Download backend artifacts
|
||||||
|
if: ${{ github.event.inputs.job_id == '' }}
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const script = require('./.github/workflows/buildScripts/downloadArtifacts.js');
|
||||||
|
await script({github, context, core, jobId: ${{env.job_id}}, name: 'webapi'});
|
||||||
|
|
||||||
58
.github/workflows/release.yml
vendored
58
.github/workflows/release.yml
vendored
@@ -1,58 +0,0 @@
|
|||||||
name: ReleaseIntoMorska
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch: # Allows manual triggering
|
|
||||||
inputs:
|
|
||||||
run-id:
|
|
||||||
description: 'ID of the run to deploy'
|
|
||||||
required: true
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: morska
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
# Step 2: Download build artifacts from another workflow (e.g., build pipeline)
|
|
||||||
- name: Download Frontend Artifacts
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
run-id: 11989658555
|
|
||||||
|
|
||||||
|
|
||||||
#- name: Copy artifacts into server
|
|
||||||
# uses: appleboy/scp-action@v0.1.7
|
|
||||||
# with:
|
|
||||||
# host: "crm.bim-it.pl"
|
|
||||||
# username: "mz"
|
|
||||||
# key: ${{ secrets.SSH_KEY }}
|
|
||||||
# port: 22
|
|
||||||
# source: "*"
|
|
||||||
# target: "/home/mz/github"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Step 3: Replace tokens in files with GitHub secrets
|
|
||||||
#- name: Replace tokens in files
|
|
||||||
# run: |
|
|
||||||
# find ./artifact -type f -exec sed -i "s/{{TOKEN_SECRET}}/${{ secrets.TOKEN_SECRET }}/g" {} \;
|
|
||||||
|
|
||||||
# Step 4: Compress the artifact folder
|
|
||||||
#- name: Compress files
|
|
||||||
# run: |
|
|
||||||
# tar -czvf release_artifact.tar.gz -C ./artifact .
|
|
||||||
|
|
||||||
# Step 5: Set up SSH agent with the private key
|
|
||||||
#- name: Setup SSH
|
|
||||||
# uses: webfactory/ssh-agent@v0.5.4
|
|
||||||
# with:
|
|
||||||
# ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
||||||
|
|
||||||
# Step 6: Upload the compressed file to the remote server via SCP
|
|
||||||
#- name: Upload to remote server
|
|
||||||
# run: |
|
|
||||||
# scp release_artifact.tar.gz ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:/path/to/destination
|
|
||||||
|
|
||||||
# Step 7: Execute a script on the remote server
|
|
||||||
#- name: Execute remote script
|
|
||||||
# run: |
|
|
||||||
# ssh ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} "bash /path/to/destination/deploy.sh"
|
|
||||||
Reference in New Issue
Block a user