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: Check job_id run: | if [ -z "${{ env.job_id }}" ]; then echo "Error: job_id is empty" exit 1 fi - name: Download frontend artifacts 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 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'}); - name: Tokenize uses: actions/github-script@v6 env: SECRETS: ${{ toJson(secrets) }} VARIABLES: ${{ toJson(vars) }} with: script: | const script = require('./.github/workflows/buildScripts/replaceTokens.js'); await script({github, context, core, jobId: ${{env.job_id}} }); - name: Archive frontend artifacts run: | cd ${{env.job_id}}/frontend zip -r ../DiunaBI-Morska-Frontend.zip . - name: Archive backend artifacts run: | cd ${{env.job_id}}/webapi zip -r ../DiunaBI-Morska-WebApi.zip . - name: List artifacts run: ls -la . - name: Send frontend archive to remote server env: SSH_PRIVATE_KEY: ${{ secrets.PROD_SRV_PRIVATE_KEY }} run: | echo "${SSH_PRIVATE_KEY}" > private_key chmod 600 private_key scp -i private_key -o StrictHostKeyChecking=no ./${{env.job_id}}/DiunaBI-Morska-Frontend.zip mz@bim-it.pl:./deployment/ rm private_key - name: Send frontend archive to remote server env: SSH_PRIVATE_KEY: ${{ secrets.PROD_SRV_PRIVATE_KEY }} run: | echo "${SSH_PRIVATE_KEY}" > private_key chmod 600 private_key scp -i private_key -o StrictHostKeyChecking=no ./${{env.job_id}}/DiunaBI-Morska-WebApi.zip mz@bim-it.pl:./deployment/ rm private_key - name: Run SSH commands on remote server env: SSH_PRIVATE_KEY: ${{ secrets.PROD_SRV_PRIVATE_KEY }} run: | echo "${SSH_PRIVATE_KEY}" > private_key chmod 600 private_key ssh -i private_key -o StrictHostKeyChecking=no mz@crm.bim-it.pl << 'EOF' ./deploy.sh EOF rm private_key