Skip to content

Commit

Permalink
update CIs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Apr 8, 2024
1 parent 3a46f5f commit 005b5eb
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 81 deletions.
8 changes: 4 additions & 4 deletions .github/actions/create-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ inputs:
npm-token:
description: 'token to push to npm registry'
required: true

runs:
using: "composite"
steps:
- working-directory: ${{ inputs.package-path }}
run: echo "Changes exist in ${{ inputs.package-path }}" && yarn npm publish --access public
run: echo "Changes exist in ${{ inputs.package-path }}" && yarn npm publish --access public
env:
NPM_TOKEN: ${{ inputs.npm-token }}
shell: bash

- working-directory: ${{ github.workspace }}
run: node ${{ github.action_path }}/gh-release-script.js ${{ github.workspace }}/${{ inputs.package-path }}
env:
run: node ${{ github.action_path }}/gh-release-script.js ${{ github.workspace }}/${{ inputs.package-path }} ${{ github.sha }}
env:
REPO_TOKEN: ${{ inputs.repo-token }}
shell: bash
107 changes: 54 additions & 53 deletions .github/actions/create-release/gh-release-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,77 @@ const myArgs = process.argv.slice(2);
const pJson = require(`${myArgs[0]}/package.json`)

const version = pJson.version;
const repoName = pJson.name;
const repoName = pJson.name;

const packageName = repoName.split('/');

function checkForBetaVersion(version) {
if (version.includes('-')){
exit(0); //skip this package but continue trying to release others
}
if (version.includes('-')){
exit(0); //skip this package but continue trying to release others
}
}

function gatherReleaseInfo(logPath) {
const changeLogs = fs.readFileSync(logPath, 'utf8');
const regex = /## \[([0-9]+(\.[0-9]+)+)] - [0-9]{4}-[0-9]{2}-[0-9]{2}/i;

let lines = changeLogs.split(/\n/);
let foundChangelog = false;
let releaseInfo = '';
let i = 0;
const changeLogs = fs.readFileSync(logPath, 'utf8');
const regex = /## \[([0-9]+(\.[0-9]+)+)] - [0-9]{4}-[0-9]{2}-[0-9]{2}/i;

for(let j = 0; j < lines.length; j++){
if(lines[j].includes(`[${version}]`)){
i = j;
j = lines.length;
foundChangelog = true;
}
}
let lines = changeLogs.split(/\n/);
let foundChangelog = false;
let releaseInfo = '';
let i = 0;

lines = lines.slice(i);

if(foundChangelog){
for(let j = 0; j < lines.length; j++){
if(j == 0){
releaseInfo += `${lines[j]}`+ '\n';
continue;
}

if(!regex.test(lines[j])){
releaseInfo += `${lines[j]}`+ '\n';
} else {
j = lines.length;
}
}
for(let j = 0; j < lines.length; j++){
if(lines[j].includes(`[${version}]`)){
i = j;
j = lines.length;
foundChangelog = true;
}

if(releaseInfo === ''){
core.setFailed("No release info found, either missing in changelog or changelog is formatted incorrectly")
}

lines = lines.slice(i);

if(foundChangelog){
for(let j = 0; j < lines.length; j++){
if(j == 0){
releaseInfo += `${lines[j]}`+ '\n';
continue;
}

if(!regex.test(lines[j])){
releaseInfo += `${lines[j]}`+ '\n';
} else {
j = lines.length;
}
}
}

if(releaseInfo === ''){
core.setFailed("No release info found, either missing in changelog or changelog is formatted incorrectly")
}

console.log("Gathered release info...")
return releaseInfo;
console.log("Gathered release info...")
return releaseInfo;
}

async function publishRelease(releaseInfo) {

await request('POST /repos/{owner}/{repo}/releases', {
headers: {
authorization: `token ${process.env.REPO_TOKEN}`,
},
owner: 'subquery',
name: `[${version}] ${repoName}`,
repo: 'subql-algorand',
tag_name: `${packageName[1]}/${version}`,
body: releaseInfo
}).catch( err => {
core.setFailed(err)
})

console.log("Release Created...")
await request('POST /repos/{owner}/{repo}/releases', {
headers: {
authorization: `token ${process.env.REPO_TOKEN}`,
},
owner: 'subquery',
name: `[${version}] ${repoName}`,
repo: 'subql',
tag_name: `${packageName[1]}/${version}`,
target_commitish: `${myArgs[1]}`,
body: releaseInfo
}).catch( err => {
core.setFailed(err)
})

console.log("Release Created...")
}

checkForBetaVersion(version);

const releaseInfo = gatherReleaseInfo(`${myArgs[0]}/CHANGELOG.md`);
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/node-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ jobs:
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
if [[ $COMMIT_MESSAGE == "[release]"* ]] && git diff --name-only HEAD~1 HEAD -- './packages/node/package.json'
then
echo "::set-output name=changes_found::true"
echo "::set-output name=changes_found::true" >> "$GITHUB_OUTPUT"
else
echo "::set-output name=changes_found::false"
echo "::set-output name=changes_found::false" >> "$GITHUB_OUTPUT"
fi
else
echo "::set-output name=changes_found::true"
echo "::set-output name=changes_found::true" >> "$GITHUB_OUTPUT"
fi
node-build-push-docker:
Expand All @@ -46,13 +46,13 @@ jobs:
token: ${{ secrets.REPO_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: onfinality
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -69,7 +69,7 @@ jobs:

- name: Build and push
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand All @@ -80,7 +80,7 @@ jobs:

- name: Build and push
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'true')
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand All @@ -104,13 +104,13 @@ jobs:
token: ${{ secrets.REPO_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: subquerynetwork
password: ${{ secrets.SQ_DOCKERHUB_TOKEN }}
Expand All @@ -127,7 +127,7 @@ jobs:

- name: Build and push
if: github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'false'
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand All @@ -138,7 +138,7 @@ jobs:

- name: Build and push
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.isLatest == 'true')
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
paths-ignore:
- '.github/workflows/**'

concurrency:
group: publish
cancel-in-progress: false

jobs:
pre-ci:
runs-on: ubuntu-latest
Expand Down
27 changes: 21 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@ on:
- '.github/workflows/**'
workflow_dispatch:

concurrency:
# Same group as prerelease
group: publish
cancel-in-progress: false

jobs:
# This gets the commit message because workflow dispatch doesnt set: github.event.head_commit.message
pre-ci:
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
commit-message: ${{ steps.step1.outputs.commit-message }}
steps:
- name: 'Block Concurrent Executions'
uses: softprops/turnstyle@v1
- uses: actions/checkout@v4
with:
poll-interval-seconds: 10
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
fetch-depth: 100

# Get the commit message, workflow_dispatch doesn't contain it so we need to get it through git cli
- id: step1
run: |
if [ -n "${{ github.event.head_commit.message }}" ]
then
echo "commit-message=${{ github.event.head_commit.message }}" >> "$GITHUB_OUTPUT"
else
echo "commit-message=$(git log -1 --pretty=%B)" >> "$GITHUB_OUTPUT"
fi
Build-Publish:
name: Build-Publish
needs: pre-ci
if: "!startsWith(github.event.head_commit.message, '[SKIP CI]') && startsWith(github.event.head_commit.message, '[release]') && github.repository == 'subquery/subql-algorand'"
if: "!startsWith(needs.pre-ci.outputs.commit-message, '[SKIP CI]') && startsWith(needs.pre-ci.outputs.commit-message, '[release]') && github.repository == 'subquery/subql'"
runs-on: ubuntu-latest
steps:
#Check out
Expand Down
15 changes: 10 additions & 5 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ FROM node:18-alpine
COPY --from=builder /app/packages/node/app.tgz /app.tgz

# Install production dependencies
RUN apk add --no-cache tini curl git && \
tar -xzvf /app.tgz --strip 1 && \
rm /app.tgz && \
yarn install --production && \
RUN apk add --no-cache tini curl git && \
apk add --no-cache python3 make g++ && \
npm install -g node-gyp

# Install the app
RUN npm i -g app.tgz

# Clean up unused deps
RUN rm /app.tgz && \
yarn cache clean && \
rm -rf /root/.npm /root/.cache

# Make the user not ROOT
USER 1000

# Set Entry point and command
ENTRYPOINT ["/sbin/tini", "--", "/bin/run"]
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/lib/node_modules/@subql/node-algorand/bin/run"]
CMD ["-f","/app"]

0 comments on commit 005b5eb

Please sign in to comment.