forked from pcaversaccio/safe-tx-hashes-util
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from OpenZeppelin/add--remove-workflows
Add new workflows and remove unused one
- Loading branch information
Showing
3 changed files
with
173 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This workflow runs whenever a release is created. | ||
# The image is tagged with latest and the release version. | ||
name: Build and Push Docker Images | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: 'arm64,amd64' | ||
|
||
- 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.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: | | ||
ghcr.io/${{ github.repository }}:latest | ||
ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
name: Create Tag and Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version_type: | ||
description: "The type of version you want to release" | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
default: 'minor' | ||
required: false | ||
|
||
jobs: | ||
check-permission: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
is-admin: ${{ steps.check-admin.outputs.is_admin }} | ||
steps: | ||
- name: Check if user is admin | ||
id: check-admin | ||
run: | | ||
IS_ADMIN=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission" | \ | ||
jq -r '.permission == "admin"') | ||
echo "is_admin=$IS_ADMIN" >> $GITHUB_OUTPUT | ||
echo "User ${{ github.actor }} is admin: $IS_ADMIN" | ||
create-release: | ||
needs: check-permission | ||
if: needs.check-permission.outputs.is-admin == 'true' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get latest tag | ||
id: get_latest_tag | ||
run: | | ||
# Ensure we fetch all tags from all remotes | ||
git fetch --tags --force | ||
# List all tags, sort by version number, and get the latest | ||
LATEST_TAG=$(git tag -l "v*" | sort -V | tail -n 1) | ||
if [ -z "$LATEST_TAG" ]; then | ||
LATEST_TAG="v0.0.0" | ||
fi | ||
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT | ||
echo "Latest tag: $LATEST_TAG" | ||
- name: Calculate new version | ||
id: calculate_version | ||
run: | | ||
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}" | ||
# Remove 'v' prefix if present | ||
VERSION=${LATEST_TAG#v} | ||
# Split version into components | ||
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION" | ||
MAJOR=${VERSION_PARTS[0]} | ||
MINOR=${VERSION_PARTS[1]} | ||
PATCH=${VERSION_PARTS[2]} | ||
# Increment based on version type | ||
case "${{ github.event.inputs.version_type }}" in | ||
major) | ||
MAJOR=$((MAJOR + 1)) | ||
MINOR=0 | ||
PATCH=0 | ||
;; | ||
minor) | ||
MINOR=$((MINOR + 1)) | ||
PATCH=0 | ||
;; | ||
patch) | ||
PATCH=$((PATCH + 1)) | ||
;; | ||
esac | ||
NEW_VERSION="v$MAJOR.$MINOR.$PATCH" | ||
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | ||
echo "New version: $NEW_VERSION" | ||
- name: Create tag | ||
run: | | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
# Fetch all tags to ensure we have the latest information | ||
git fetch --tags | ||
# Check if tag already exists | ||
if git rev-parse --verify --quiet "refs/tags/${{ steps.calculate_version.outputs.new_version }}" >/dev/null; then | ||
echo "Tag ${{ steps.calculate_version.outputs.new_version }} already exists, skipping tag creation" | ||
else | ||
echo "Creating tag ${{ steps.calculate_version.outputs.new_version }}" | ||
git tag ${{ steps.calculate_version.outputs.new_version }} | ||
git push origin ${{ steps.calculate_version.outputs.new_version }} | ||
fi | ||
- name: Create release | ||
run: | | ||
# Check if release already exists | ||
if gh release view ${{ steps.calculate_version.outputs.new_version }} &>/dev/null; then | ||
echo "Release ${{ steps.calculate_version.outputs.new_version }} already exists, skipping release creation" | ||
else | ||
echo "Creating release ${{ steps.calculate_version.outputs.new_version }}" | ||
gh release create ${{ steps.calculate_version.outputs.new_version }} \ | ||
--generate-notes \ | ||
--title "Release ${{ steps.calculate_version.outputs.new_version }}" \ | ||
--draft | ||
fi | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
|
||
unauthorized: | ||
needs: check-permission | ||
if: needs.check-permission.outputs.is-admin != 'true' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Unauthorized message | ||
run: | | ||
echo "Error: Only repository administrators can create releases" | ||
exit 1 |