Skip to content

Commit 4f8f320

Browse files
Merge pull request #17 from OpenZeppelin/add--remove-workflows
Add new workflows and remove unused one
2 parents 8a8873e + 48d1d5d commit 4f8f320

File tree

3 files changed

+173
-25
lines changed

3 files changed

+173
-25
lines changed

.github/workflows/checks.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/docker.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This workflow runs whenever a release is created.
2+
# The image is tagged with latest and the release version.
3+
name: Build and Push Docker Images
4+
5+
on:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
with:
22+
platforms: 'arm64,amd64'
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.repository_owner }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Build and push Docker image
35+
uses: docker/build-push-action@v5
36+
with:
37+
context: .
38+
platforms: linux/amd64,linux/arm64
39+
push: true
40+
tags: |
41+
ghcr.io/${{ github.repository }}:latest
42+
ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }}
43+
cache-from: type=gha
44+
cache-to: type=gha,mode=max

.github/workflows/release.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Create Tag and Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: "The type of version you want to release"
8+
type: choice
9+
options:
10+
- patch
11+
- minor
12+
- major
13+
default: 'minor'
14+
required: false
15+
16+
jobs:
17+
check-permission:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
is-admin: ${{ steps.check-admin.outputs.is_admin }}
21+
steps:
22+
- name: Check if user is admin
23+
id: check-admin
24+
run: |
25+
IS_ADMIN=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
26+
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission" | \
27+
jq -r '.permission == "admin"')
28+
echo "is_admin=$IS_ADMIN" >> $GITHUB_OUTPUT
29+
echo "User ${{ github.actor }} is admin: $IS_ADMIN"
30+
31+
create-release:
32+
needs: check-permission
33+
if: needs.check-permission.outputs.is-admin == 'true'
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v3
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Get latest tag
42+
id: get_latest_tag
43+
run: |
44+
# Ensure we fetch all tags from all remotes
45+
git fetch --tags --force
46+
47+
# List all tags, sort by version number, and get the latest
48+
LATEST_TAG=$(git tag -l "v*" | sort -V | tail -n 1)
49+
if [ -z "$LATEST_TAG" ]; then
50+
LATEST_TAG="v0.0.0"
51+
fi
52+
53+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
54+
echo "Latest tag: $LATEST_TAG"
55+
56+
- name: Calculate new version
57+
id: calculate_version
58+
run: |
59+
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
60+
# Remove 'v' prefix if present
61+
VERSION=${LATEST_TAG#v}
62+
63+
# Split version into components
64+
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION"
65+
MAJOR=${VERSION_PARTS[0]}
66+
MINOR=${VERSION_PARTS[1]}
67+
PATCH=${VERSION_PARTS[2]}
68+
69+
# Increment based on version type
70+
case "${{ github.event.inputs.version_type }}" in
71+
major)
72+
MAJOR=$((MAJOR + 1))
73+
MINOR=0
74+
PATCH=0
75+
;;
76+
minor)
77+
MINOR=$((MINOR + 1))
78+
PATCH=0
79+
;;
80+
patch)
81+
PATCH=$((PATCH + 1))
82+
;;
83+
esac
84+
85+
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
86+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
87+
echo "New version: $NEW_VERSION"
88+
89+
- name: Create tag
90+
run: |
91+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
92+
git config --local user.name "github-actions[bot]"
93+
94+
# Fetch all tags to ensure we have the latest information
95+
git fetch --tags
96+
97+
# Check if tag already exists
98+
if git rev-parse --verify --quiet "refs/tags/${{ steps.calculate_version.outputs.new_version }}" >/dev/null; then
99+
echo "Tag ${{ steps.calculate_version.outputs.new_version }} already exists, skipping tag creation"
100+
else
101+
echo "Creating tag ${{ steps.calculate_version.outputs.new_version }}"
102+
git tag ${{ steps.calculate_version.outputs.new_version }}
103+
git push origin ${{ steps.calculate_version.outputs.new_version }}
104+
fi
105+
106+
- name: Create release
107+
run: |
108+
# Check if release already exists
109+
if gh release view ${{ steps.calculate_version.outputs.new_version }} &>/dev/null; then
110+
echo "Release ${{ steps.calculate_version.outputs.new_version }} already exists, skipping release creation"
111+
else
112+
echo "Creating release ${{ steps.calculate_version.outputs.new_version }}"
113+
gh release create ${{ steps.calculate_version.outputs.new_version }} \
114+
--generate-notes \
115+
--title "Release ${{ steps.calculate_version.outputs.new_version }}" \
116+
--draft
117+
fi
118+
env:
119+
GH_TOKEN: ${{ github.token }}
120+
121+
unauthorized:
122+
needs: check-permission
123+
if: needs.check-permission.outputs.is-admin != 'true'
124+
runs-on: ubuntu-latest
125+
steps:
126+
- name: Unauthorized message
127+
run: |
128+
echo "Error: Only repository administrators can create releases"
129+
exit 1

0 commit comments

Comments
 (0)