From 52f213f1449889e749893988c373e0e6ca1e1db8 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Mon, 22 Apr 2024 20:21:21 -0400 Subject: [PATCH] feat: setup semantic release --- .github/workflows/delete_untagged.py | 25 ++++++++++ .github/workflows/release.yml | 69 ++++++++++++++++++++++++++++ .releaserc.yaml | 15 ++++++ package.json | 16 +++++++ 4 files changed, 125 insertions(+) create mode 100755 .github/workflows/delete_untagged.py create mode 100644 .github/workflows/release.yml create mode 100644 .releaserc.yaml create mode 100644 package.json diff --git a/.github/workflows/delete_untagged.py b/.github/workflows/delete_untagged.py new file mode 100755 index 0000000..c89492e --- /dev/null +++ b/.github/workflows/delete_untagged.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import argparse +import json +import requests +import types + +parser = argparse.ArgumentParser() +parser.add_argument("token", help="GitHub token") +args = parser.parse_args() + +domain = "api.github.com" +org = "BNLNPPS" +package_type = "container" +package_name = "esi-opticks" + +api_url = f"https://{domain}/orgs/{org}/packages/{package_type}/{package_name}/versions" + +respjson = requests.get(api_url, auth=("token", args.token)) +entries = json.loads(respjson.text, object_hook=lambda d: types.SimpleNamespace(**d)) + +for e in entries: + if not e.metadata.container.tags: + response = requests.delete(api_url + f"/{e.id}", auth=("token", args.token)) + print("delete", e.id, e.html_url, e.name, response.url, response.status_code) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..884e04f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,69 @@ +name: Release + +on: + push: + branches: + - semrel + +jobs: + build-test-release: + runs-on: ubuntu-latest + steps: + - name: Define environment variables + run: echo IMAGE_NAME=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Important for Semantic Release to analyze all commits + + - name: Set up Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build container + uses: docker/build-push-action@v5 + with: + tags: ${{ env.IMAGE_NAME }}:prerel + load: true + push: true + cache-from: | + ${{ env.IMAGE_NAME }}:latest + ${{ env.IMAGE_NAME }}:prerel + + - name: Run tests + run: docker run ${{ env.IMAGE_NAME }}:prerel curl --version + + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + id: semantic + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ steps.semantic.outputs.new_release_git_tag }} + + - name: Build container + uses: docker/build-push-action@v5 + with: + tags: | + ${{ env.IMAGE_NAME }}:latest + ${{ env.IMAGE_NAME }}:${{ steps.semantic.outputs.new_release_version }} + push: true + cache-from: ${{ env.IMAGE_NAME }}:prerel + + cleanup: + runs-on: ubuntu-latest + needs: build-test-release + steps: + - name: Checkout code + uses: actions/checkout@v4 + - run: .github/workflows/delete_untagged.py ${{ secrets.GITHUB_TOKEN }} diff --git a/.releaserc.yaml b/.releaserc.yaml new file mode 100644 index 0000000..5be77ac --- /dev/null +++ b/.releaserc.yaml @@ -0,0 +1,15 @@ +# See https://semantic-release.gitbook.io/semantic-release/usage/configuration +branches: + - semrel +tagFormat: '${version}' # without this, the tag is prefixed with a 'v' +plugins: + - "@semantic-release/commit-analyzer" + - "@semantic-release/release-notes-generator" + - "@semantic-release/changelog" + - path: "@semantic-release/npm" + npmPublish: false + - path: "@semantic-release/git" + assets: + - "CHANGELOG.md" + - "package.json" + message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}" diff --git a/package.json b/package.json new file mode 100644 index 0000000..7e9ef06 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "esi-opticks", + "version": "0.0.0", + "description": "EIC Simulation Infrastructure", + "repository": { + "type": "git", + "url": "git+https://github.com/BNLNPPS/esi-opticks.git" + }, + "keywords": [], + "author": "BNL NPPS", + "license": "MIT", + "bugs": { + "url": "https://github.com/BNLNPPS/esi-opticks/issues" + }, + "homepage": "https://github.com/BNLNPPS/esi-opticks#readme" +}