Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ts): does not mark ts release as latest in github #146

Merged
merged 10 commits into from
Apr 17, 2024
21 changes: 5 additions & 16 deletions .github/workflows/release-ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
branches:
- main

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

jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -27,14 +31,6 @@ jobs:
cache: npm
cache-dependency-path: ts/package-lock.json

- name: Restore node_modules cache
id: deps-cache
if: steps.changes.outputs.ts == 'true' && steps.deps-cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/restore@v3
with:
path: ts/node_modules
key: ${{ runner.os }}-build-ts-deps-cache-${{ hashFiles('ts/package-lock.json') }}

- name: Setup env
if: steps.changes.outputs.ts == 'true'
uses: HatsuneMiku3939/direnv-action@v1
Expand All @@ -46,7 +42,7 @@ jobs:
- name: Publish npm package
if: steps.changes.outputs.ts == 'true'
env:
GITHUB_TOKEN: ${{ secrets.AUTH_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: make release-ts

Expand All @@ -56,10 +52,3 @@ jobs:
files: ./ts/coverage
token: ${{ secrets.CODECOV_TOKEN }}

- name: Cache node modules
if: steps.deps-cache.outputs.cache-hit != 'true' && steps.changes.outputs.ts == 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: ts/node_modules
key: ${{ runner.os }}-build-ts-deps-cache-${{ hashFiles('ts/package-lock.json') }}

10 changes: 10 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- main

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

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -30,6 +34,12 @@ jobs:
- run: |
toolchain=$(./script/tools.sh gotoolchain | sed 's/go*//')
echo "GOVERSION=${toolchain}" >> $GITHUB_ENV
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.8.1
cache: npm
cache-dependency-path: ts/package-lock.json
- uses: actions/setup-go@v5
with:
go-version: "${{ env.GOVERSION }}"
Expand Down
6 changes: 1 addition & 5 deletions make/release-ts.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
.PHONY: release-ts
release-ts: $(AKASH_TS_NODE_MODULES) $(AKASH_TS_ROOT)/dist
if [ -z "$$CI" ]; then \
cd $(AKASH_TS_ROOT) && npx semantic-release --no-ci; \
else \
cd $(AKASH_TS_ROOT) && npx semantic-release; \
fi
script/release-ts.sh

$(AKASH_TS_ROOT)/dist: $(shell find $(AKASH_TS_ROOT)/src -type f)
cd $(AKASH_TS_ROOT) && npm run build
54 changes: 54 additions & 0 deletions script/release-ts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-$GITHUB_ACTION_REPOSITORY}

if [ -z "$GITHUB_REPOSITORY" ]; then
echo "Error: GITHUB_REPOSITORY or GITHUB_ACTION_REPOSITORY is not set."
exit 1
fi

if [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_TOKEN is not set."
exit 1
fi

API_URL="https://api.github.com"

ygrishajev marked this conversation as resolved.
Show resolved Hide resolved
log() {
echo "$(date +"[%I:%M:%S %p]") [ts-release] $1"
}

log "Fetching the current latest release information..."
current_latest=$(curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
"$API_URL/repos/$GITHUB_REPOSITORY/releases/latest")
current_latest_id=$(echo "$current_latest" | jq -r '.id')

if [ "$current_latest_id" == "null" ]; then
log "No current latest release found."
exit 1
else
log "Current latest release ID: $current_latest_id"
fi

log "Running semantic-release..."
if [ -z "$CI" ]; then
log "Running in non-CI mode..."
cd "$AKASH_TS_ROOT" && npx semantic-release --no-ci
else
log "Running in CI mode..."
cd "$AKASH_TS_ROOT" && npx semantic-release
fi

log "Attempting to mark the release (ID: $current_latest_id) as the latest again..."
update_response=$(curl -s -X PATCH -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -H "Accept: application/vnd.github.v3+json" \
-d "{\"make_latest\": \"true\"}" \
"$API_URL/repos/$GITHUB_REPOSITORY/releases/$current_latest_id")

log "Update response:"
echo "$update_response" | jq

if echo "$update_response" | jq -e '.id'; then
log "The release was successfully marked as the latest."
else
log "Failed to update the release. Check the response above for errors."
fi
1 change: 1 addition & 0 deletions ts/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
jest.config.js
tsconfig.build.json
tsconfig.json
.eslintrc.json

# Source and test files
src
Expand Down
2 changes: 1 addition & 1 deletion ts/.releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
]
],
"preset": "angular",
"preset": "conventionalcommits",
troian marked this conversation as resolved.
Show resolved Hide resolved
"working_directory": "ts",
"branches": [
{
Expand Down
1 change: 1 addition & 0 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![npm version](https://badge.fury.io/js/%40akashnetwork%2Fakash-api.svg)](https://badge.fury.io/js/%40akashnetwork%2Fakash-api)
[![License: Apache-2.0](https://img.shields.io/badge/License-apache2.0-yellow.svg)](https://opensource.org/license/apache-2-0)
[![semantic-release: conventionalcommits](https://img.shields.io/badge/semantic--release-conventionalcommits?logo=semantic-release)](https://github.com/semantic-release/semantic-release)

This package provides TypeScript bindings for the Akash API, generated from protobuf definitions.

Expand Down
1 change: 1 addition & 0 deletions ts/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
collectCoverageFrom: [
'<rootDir>/src/**/*.{js,ts}',
'!<rootDir>/src/generated/**/*',
'!<rootDir>/src/patch/index.*',
],
projects: [
{
Expand Down
2 changes: 0 additions & 2 deletions ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
},
"description": "Akash API TypeScript client",
"devDependencies": {
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^12.0.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^10.0.3",
"@semantic-release/release-notes-generator": "^13.0.0",
"@types/jest": "^29.5.12",
Expand Down
Loading