Skip to content

Commit

Permalink
feat: setup semantic release
Browse files Browse the repository at this point in the history
  • Loading branch information
plexoos committed Apr 25, 2024
1 parent 23183af commit 52f213f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/delete_untagged.py
Original file line number Diff line number Diff line change
@@ -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)
69 changes: 69 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
15 changes: 15 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -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}"
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 52f213f

Please sign in to comment.