Skip to content

release

release #31

Workflow file for this run

name: release
on:
workflow_dispatch:
inputs:
release_description:
description: 'Release description'
required: true
type: string
jobs:
createRelease:
name: Merge release branch into master
runs-on: ubuntu-latest
steps:
- name: extract version from branch name by removing release/ prefix
id: extract-version
run: |
echo "version=${GITHUB_REF#refs/heads/release/}" >> $GITHUB_OUTPUT
- name: Fail if version is empty
if: ${{ steps.extract-version.outputs.version == '' }}
run: exit 1
- name: Checkout master
uses: actions/checkout@v3
with:
ref: master
fetch-depth: 0
- name: merge current branch into master
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git merge --no-edit --no-ff -m "merge(release/${{ steps.extract-version.outputs.version }}): ${{ github.event.inputs.release_description }}" origin/release/${{ steps.extract-version.outputs.version }}
git push origin master
- name: Create tag
run: |
git tag ${{ steps.extract-version.outputs.version }}
git push origin ${{ steps.extract-version.outputs.version }}
- name: Download artifact from latest workflow run on branch
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require("fs");
const path = require("path");
const workflowName = 'build';
const branchName = process.env.GITHUB_REF.split('/').slice(2).join('/');
const artifactNames = ['release', 'installer'];
const workflows = await github.rest.actions.listRepoWorkflows({
owner: context.repo.owner,
repo: context.repo.repo,
});
// Log all workflows as json
// console.log(JSON.stringify(workflows.data, null, 2));
const workflow = workflows.data.workflows.find(w => w.name === workflowName);
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1,
branch: branchName,
workflow_id: workflow.id,
status: 'success',
});
// Log all workflows as json
// console.log(JSON.stringify(runs.data, null, 2));
const runId = runs.data.workflow_runs[0].id;
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId,
});
// Log all workflows as json
// console.log(JSON.stringify(artifacts.data, null, 2));
const artifactIds = {};
for (const name of artifactNames) {
const artifact = artifacts.data.artifacts.find(a => a.name === name);
if (artifact) {
artifactIds[name] = artifact.id;
} else {
console.log(`Artifact ${name} not found in latest workflow run.`);
}
}
const targetDir = '.artifacts';
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
for (const [name, id] of Object.entries(artifactIds)) {
const response = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: id,
archive_format: 'zip',
});
const filePath = path.join(targetDir, `${name}.zip`);
fs.writeFileSync(filePath, Buffer.from(response.data));
}
- name: Unzip .artifacts
run: |
unzip .artifacts/release.zip -d .artifacts
unzip .artifacts/installer.zip -d .artifacts
mv .artifacts/MonitorrentInstaller.exe .artifacts/MonitorrentInstaller-${{ steps.extract-version.outputs.version }}.exe
rm .artifacts/release.zip
rm .artifacts/installer.zip
- name: Create release
uses: ncipollo/release-action@v1
with:
artifacts: .artifacts/*
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.extract-version.outputs.version }} - ${{ github.event.inputs.release_description }}
tag: ${{ steps.extract-version.outputs.version }}
makeLatest: true
bodyFile: RELEASE_NOTES.md
draft: false
prerelease: false
- name: Find release zip in downloaded artifacts
id: find-release-zip
run: |
echo "release-zip=$(ls .artifacts/monitorrent-*.zip)" >> $GITHUB_OUTPUT
- name: Unzip release zip to dist folder
run: unzip ${{ steps.find-release-zip.outputs.release-zip }} -d ./dist
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build docker image
run: |-
sed "s/COPY --from=build/COPY --from=mount/g" Dockerfile | \
docker buildx build \
--platform linux/arm64,linux/amd64 \
-t werwolfby/monitorrent:${{ steps.extract-version.outputs.version }} \
-t werwolfby/monitorrent:latest \
--push -f - .
- name: Merge into develop
run: |
git checkout develop
git merge --no-edit --no-ff -m "merge(master): merge back" origin/master
git push origin develop