Skip to content

Commit

Permalink
ci: add build and publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 9, 2024
1 parent 16b7a60 commit 52f7eed
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 40 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/auto-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Auto Tag

on:
push:
branches:
- main

concurrency:
group: main-release-check

jobs:
release:
name: release
runs-on: ubuntu-latest
steps:
- name: Clean workspace
uses: Chia-Network/actions/clean-workspace@main

- name: Checkout current branch
uses: actions/checkout@v3
with:
# Need PACKAGE_ADMIN_PAT token so when the tag is created, the tag automation runs
token: ${{ secrets.GH_ACCESS_TOKEN }}
fetch-depth: 0

- name: Set Git identity
run: |
git config --local user.email "[email protected]"
git config --local user.name "Automation"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version from package.json
run: |
VERSION=$(jq -r '.version' package.json)
echo "Extracted version: $VERSION"
# Set the version as an output for other steps to use
echo "VERSION=$VERSION" >> $GITHUB_ENV
if git tag --list | grep -q "^$VERSION$"; then
echo "Tag $VERSION already exists, nothing to do."
else
echo "Tag does not exist. Creating and pushing tag."
git tag $VERSION -m "Release $VERSION"
git push origin $VERSION
fi
shell: bash
90 changes: 90 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build and Push Docker

on:
push:
tags:
- '**'

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
build:
name: Build Node.js and Push Docker
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'

- name: Install Dependencies
run: npm ci

- name: Build Project
run: npm run build

- name: Extract Project Name
id: project-name
run: |
PROJECT_NAME=$(jq -r '.name' package.json)
if [ -z "$PROJECT_NAME" ]; then
echo "Project name not found in package.json!"
exit 1
fi
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV
- name: Debug GITHUB_REF
run: |
echo "GITHUB_REF: $GITHUB_REF"
- name: Get tag name
id: tag-name
run: |
TAGNAME=$(echo $GITHUB_REF | sed 's/refs\/tags\///')
if [ -z "$TAGNAME" ]; then
echo "TAGNAME is empty!"
exit 1
fi
echo "TAGNAME=$TAGNAME" >> $GITHUB_ENV
- name: Determine Docker Tag
id: docker-tag
run: |
if [[ "$TAGNAME" == *"alpha"* ]]; then
echo "DOCKER_TAG=latest-alpha" >> $GITHUB_ENV
else
echo "DOCKER_TAG=latest" >> $GITHUB_ENV
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and Push Docker Image
run: |
echo "Building and pushing Docker image..."
echo "PROJECT_NAME: ${{ env.PROJECT_NAME }}"
echo "DOCKER_TAG: ${{ env.DOCKER_TAG }}"
echo "TAGNAME: ${{ env.TAGNAME }}"
# Ensure PROJECT_NAME, DOCKER_TAG, and TAGNAME are not empty
if [ -z "${{ env.PROJECT_NAME }}" ] || [ -z "${{ env.DOCKER_TAG }}" ] || [ -z "${{ env.TAGNAME }}" ]; then
echo "Error: One of the required variables is empty!"
exit 1
fi
docker build -t ${{ vars.DOCKER_NAMESPACE }}/${{ env.PROJECT_NAME }}:${{ env.DOCKER_TAG }} .
docker tag ${{ vars.DOCKER_NAMESPACE }}/${{ env.PROJECT_NAME }}:${{ env.DOCKER_TAG }} ${{ vars.DOCKER_NAMESPACE }}/${{ env.PROJECT_NAME }}:${{ env.TAGNAME }}
docker push ${{ vars.DOCKER_NAMESPACE }}/${{ env.PROJECT_NAME }}:${{ env.DOCKER_TAG }}
docker push ${{ vars.DOCKER_NAMESPACE }}/${{ env.PROJECT_NAME }}:${{ env.TAGNAME }}
47 changes: 47 additions & 0 deletions .github/workflows/ensure-version-increment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow runs on any PRs that are targeting main and ensures that the version in package.json is incremented
name: Check Version Increment

on:
pull_request:
branches:
- 'main'

concurrency:
# SHA is added to the end if on `main` to let all main workflows run
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }}
cancel-in-progress: true

jobs:
check-version:
name: Check version increment
runs-on: ubuntu-latest
steps:
- uses: Chia-Network/actions/clean-workspace@main

- name: Checkout current branch
uses: actions/checkout@v3
with:
path: branch-repo

- name: Checkout main
uses: actions/checkout@v3
with:
ref: main
path: main-repo

- name: Check Versions
run: |
# Extract version from main branch's package.json
mainVersion=$(jq -r '.version' main-repo/package.json)
echo "Main version: $mainVersion"
# Extract version from current branch's package.json
branchVersion=$(jq -r '.version' branch-repo/package.json)
echo "Branch version: $branchVersion"
# Compare versions
if [ "$branchVersion" == "$mainVersion" ]; then
echo "Version in package.json on this branch is not incremented. Version must increment for a merge to main."
exit 1
fi
shell: bash
43 changes: 3 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dig-cli",
"name": "dig-propagation-server",
"version": "1.0.0-alpha.1",
"description": "",
"type": "commonjs",
Expand All @@ -14,11 +14,7 @@
"start": "ts-node src/index.ts",
"server": "ts-node src/server.ts",
"test": "mocha -r ts-node/register tests.ts",
"release": "standard-version",
"postrelease": "npm run build && git push --follow-tags && npm publish",
"start-propagation-server": "ts-node src/propagation_server/index.ts",
"build-propagation-server": "docker build -t dig-propagation-server -f Dockerfile.propagation_server .",
"release-docker": "npm run build-propagation-server && docker tag dig-propagation-server michaeltaylor3d/dig-propagation-server:1.0.0-alpha.1 && docker push michaeltaylor3d/dig-propagation-server:1.0.0-alpha.1"
"release": "bash ./scripts/release.sh"
},
"author": "",
"license": "ISC",
Expand All @@ -29,49 +25,16 @@
],
"dependencies": {
"async-mutex": "^0.5.0",
"bip39": "^3.1.0",
"chia-bls": "^1.0.2",
"chia-config-loader": "^1.0.1",
"chia-root-resolver": "^1.0.0",
"chia-server-coin": "^0.0.5",
"chia-wallet": "^1.0.18",
"cli-progress": "^3.12.0",
"crypto-js": "^4.2.0",
"datalayer-driver": "^0.1.21",
"dig-cli": "^0.0.49",
"express": "^4.19.2",
"fs-extra": "^11.2.0",
"ignore": "^5.3.2",
"inquirer": "^10.1.8",
"ipify": "^6.0.0",
"keytar": "^7.9.0",
"lodash": "^4.17.21",
"merkletreejs": "^0.4.0",
"nanospinner": "^1.1.0",
"nconf": "^0.12.1",
"public-ip": "^7.0.1",
"superagent": "^10.0.0",
"toad-scheduler": "^3.0.1",
"yargs": "^17.7.2"
"toad-scheduler": "^3.0.1"
},
"devDependencies": {
"@types/chai": "^4.3.17",
"@types/cli-progress": "^3.11.6",
"@types/crypto-js": "^4.2.2",
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.7",
"@types/keytar": "^4.4.2",
"@types/lodash": "^4.17.7",
"@types/mocha": "^10.0.7",
"@types/nconf": "^0.10.7",
"@types/node": "^22.1.0",
"@types/superagent": "^8.1.8",
"@types/yargs": "^17.0.33",
"chai": "^5.1.1",
"copyfiles": "^2.4.1",
"mocha": "^10.7.0",
"standard-version": "^9.5.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
}
Expand Down
37 changes: 37 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo "You have uncommitted changes. Please commit or stash them before running this script."
exit 1
fi

# Ensure we're on the develop branch
CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" != "develop" ]; then
echo "You must be on the 'develop' branch to run this script."
exit 1
fi

# Run standard-version for version bumping
npx standard-version --prerelease alpha

# Extract the new version from package.json after bumping
NEW_VERSION=$(jq -r '.version' package.json)

# Create a new feature branch based on the new version
FEATURE_BRANCH="release/v$NEW_VERSION"
git checkout -b "$FEATURE_BRANCH"

# Commit changes
git add .
git commit -m "chore(release): bump version to $NEW_VERSION"
git push --set-upstream origin "$FEATURE_BRANCH"

# Notify the user about the feature branch
echo "Version bumped and committed on branch $FEATURE_BRANCH."

# Instructions for further actions (manual steps)
echo "Next steps:"
echo "- Review the changes in the feature branch."
echo "- Push the branch to the remote repository if necessary."

0 comments on commit 52f7eed

Please sign in to comment.