Skip to content

Commit

Permalink
[#2] workflows: import the basic set of actions
Browse files Browse the repository at this point in the history
Copied from the self provisioning plugin. This should cover the basic
needs to start this repo.
  • Loading branch information
lavocatt committed Jul 16, 2024
1 parent 48ec238 commit 193d33f
Show file tree
Hide file tree
Showing 7 changed files with 351 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

PLUGIN_VERSION=1.0.0
PLUGIN_NAME='ActiveMQ Artemis Jolokia api-server'

# dev cert
SERVER_CERT=/var/serving-cert/tls.crt
SERVER_KEY=/var/serving-cert/tls.key

# replace the token in production deployment
SECRET_ACCESS_TOKEN=1e13d44f998dee277deae621a9012cf300b94c91

# to trust jolokia certs
NODE_TLS_REJECT_UNAUTHORIZED='0'
33 changes: 33 additions & 0 deletions .github/actions/cache-restore/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Cache restoration and install node_modules'
description: 'Install node_modules and restore cache if any'

runs:
using: 'composite'
steps:
- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: |
echo "dir=$(yarn cache dir)" >>$GITHUB_OUTPUT
- name: Get node version
id: node
shell: bash
run: |
echo "version=$(node -v)" >>$GITHUB_OUTPUT
- name: Get node_modules cache
uses: actions/cache@v3
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
**/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ steps.node.outputs.version }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ steps.node.outputs.version }}
- name: Install Dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
shell: bash
run: yarn install --frozen-lockfile --network-timeout 1000000
25 changes: 25 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["config:base", ":pinAllExceptPeerDependencies"],
"groupName": "all",
"automerge": true,
"major": {
"automerge": false
},
"transitiveRemediation": true,
"packageRules": [
{
"matchPackageNames": ["react", "react-dom", "react-test-renderer"],
"groupName": "React Core",
"allowedVersions": "17.0.2",
"automerge": true
},
{
"matchPackageNames": ["react-router-dom"],
"groupName": "React Router Dom",
"allowedVersions": "5.2.1",
"automerge": true
}
],
"separateMajorMinor": true,
"separateMultipleMajor": true
}
146 changes: 146 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: CI

env:
IMAGE_NAME: activemq-artemis-jolokia-api-server

on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '6 0 * * *'
workflow_dispatch:
inputs:
snapshot:
description: 'Snapshot'
required: false
default: false
type: boolean

# cancels the old active workflow if new workflow is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

openapi:
name: Check that the openapi file is in sync with the generated files
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

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

- name: Get cache and install dependencies
uses: ./.github/actions/cache-restore

- name: regenerate the api.md
continue-on-error: true
run: yarn build-api-doc && yarn pretty-quick

- name: check there is no manual changes
run: git diff && [ -z "$(git status --porcelain=v1 2>/dev/null)" ] && echo "✓ No manual changes." || echo "✗ api.md manually changed, please refer to the api.md for the procedure to follow for programmatically generated endpoints." && [ -z "$(git status --porcelain=v1 2>/dev/null)" ]

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v3

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

- name: Get cache and install dependencies
uses: ./.github/actions/cache-restore

- name: Build project
run: yarn run build

- name: Run the test suite
run: yarn test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Check for uncommited changes
run: git diff --quiet --exit-code

- name: Set outputs
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "date=$(date +%Y%m%d)" >> $GITHUB_OUTPUT
- name: Check outputs
run: |
echo ${{ steps.vars.outputs.sha_short }}
echo ${{ steps.vars.outputs.date }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Build the image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: dev.latest dev.${{ steps.vars.outputs.date }}.${{ steps.vars.outputs.sha_short }}
# If this is a PR, we only build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work.
# If this is not a PR (e.g. a tag or merge commit), also build for ARM64
platforms: linux/amd64${{github.event_name!='pull_request' && ',linux/arm64' || ''}}
context: .
dockerfiles: |
./Dockerfile
labels: |
quay.expires-after=90d
git-sha=$GITHUB_SHA
- name: Push the dev image to quay.io
# Only login if not a PR, as PRs only trigger a Docker build and not a push
if: ${{ github.event_name != 'pull_request' }}
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/${{ secrets.QUAY_NAMESPACE }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release

env:
IMAGE_NAME: activemq-artemis-jolokia-api-server

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v3

- name: Create release tag
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
git fetch --tags
HEAD_COMMIT="$(git rev-parse HEAD)"
RELEASE_TAG="$(cat package.json | jq -r '.version')"
RELEASE_TAG_COMMIT="$(git rev-list -n 1 ${RELEASE_TAG} || true)"
if [ "$RELEASE_TAG_COMMIT" != "$HEAD_COMMIT" ]; then
git config user.name 'artemiscloud-bot'
git config user.email '[email protected]'
git tag -a ${RELEASE_TAG} -m ${RELEASE_TAG} --force
git push origin $RELEASE_TAG --force
fi
- name: Set outputs
id: vars
run: |
echo "image_tag=$(git describe --exact-match --tags | sed 's/v//')" >> $GITHUB_OUTPUT
- name: Check outputs
run: |
echo ${{ steps.vars.outputs.image_tag }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Build the image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: latest ${{ steps.vars.outputs.image_tag }}
platforms: linux/amd64, linux/arm64
context: .
dockerfiles: |
./Dockerfile
- name: Push the image to quay.io
id: push-to-quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/${{ secrets.QUAY_NAMESPACE }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
71 changes: 71 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Update

env:
IMAGE_NAME: activemq-artemis-jolokia-api-server

on:
workflow_dispatch:
inputs:
version:
description: 'Version, i.e. 1.0.0'
required: false
default: '*.*.+'
type: string
update_version:
description: 'Update version'
required: true
default: true
type: boolean
trigger_release:
description: 'Trigger release'
required: false
default: true
type: boolean

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout the repo
uses: actions/checkout@v3

- name: Set up the repo
run: |
git config user.name 'artemiscloud-bot'
git config user.email '[email protected]'
git push
- name: Update version
if: ${{ inputs.update_version }}
run: |
CURRENT_VERSION=$(cat package.json | jq -r '.version')
IFS=. read CURRENT_VERSION_MAJOR CURRENT_VERSION_MINOR CURRENT_VERSION_PATCH <<< ${CURRENT_VERSION}
IFS=. read VERSION_MAJOR VERSION_MINOR VERSION_PATCH <<< ${{ inputs.version }}
VERSION_MAJOR=${VERSION_MAJOR/\*/${CURRENT_VERSION_MAJOR}} && VERSION_MAJOR=${VERSION_MAJOR/+/$((CURRENT_VERSION_MAJOR+1))}
VERSION_MINOR=${VERSION_MINOR/\*/${CURRENT_VERSION_MINOR}} && VERSION_MINOR=${VERSION_MINOR/+/$((CURRENT_VERSION_MINOR+1))}
VERSION_PATCH=${VERSION_PATCH/\*/${CURRENT_VERSION_PATCH}} && VERSION_PATCH=${VERSION_PATCH/+/$((CURRENT_VERSION_PATCH+1))}
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
PACKAGE_JSON_CONTENTS=$(jq '.version="'"$VERSION"'" \
| .consolePlugin.version="'"$VERSION"'" \
| ._id="activemq-artemis-jolokia-api-server@'$VERSION'"' package.json) \
&& echo -E "${PACKAGE_JSON_CONTENTS}" > package.json && unset PACKAGE_JSON_CONTENTS
sed -i "s~^LABEL version=.*~LABEL version=\"${VERSION}\"~g" Dockerfile
git commit --all --message "Update version to ${VERSION}" || echo "nothing to commit"
- name: Push commits
run: |
git push
- name: Trigger release
if: ${{ inputs.trigger_release }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release.yml',
ref: context.ref,
});
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ web_modules/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
Expand Down

0 comments on commit 193d33f

Please sign in to comment.