Merge pull request #464 from rtfpessoa/test-actions

Migrate to GitHub Actions
This commit is contained in:
Rodrigo Fernandes 2023-01-06 21:58:30 +00:00 committed by GitHub
commit 88b06ef3e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 189 additions and 270 deletions

View file

@ -1,219 +0,0 @@
version: 2.1
jobs:
checkout-and-version:
docker:
- image: codacy/git-version
working_directory: ~/workdir
steps:
- checkout
- run:
name: Get next version
command: |
export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=master)"
echo "Next version is ${NEXT_VERSION}"
echo "${NEXT_VERSION}" > .version
- run:
name: Get next npm tag name
command: |
if [ "${CIRCLE_BRANCH}" = "master" ]; then
export PUBLISH_TAG="latest"
elif [ "${CIRCLE_BRANCH}" = "next" ]; then
export PUBLISH_TAG="next"
else
export PUBLISH_TAG="pr"
fi
echo "Next tag is ${PUBLISH_TAG}"
echo "${PUBLISH_TAG}" > .tag
- persist_to_workspace:
root: ~/workdir
paths:
- '*'
build-common: &build-common
docker:
- image: node
working_directory: ~/workdir
steps:
- attach_workspace:
at: ~/workdir
- restore_cache:
key: yarn-cache-{{ checksum "yarn.lock" }}
- run:
name: Log environment setup
command: |
node -v
yarn -v
- run:
name: Install dependencies
command: yarn install --ignore-engines
- save_cache:
key: yarn-cache-{{ checksum "yarn.lock" }}
paths:
- /usr/local/share/.cache/yarn
- run:
name: Build templates
command: yarn run build:templates
- run:
name: Build library
command: yarn run build
build-stable: &build-stable
docker:
- image: node
working_directory: ~/workdir
steps:
- attach_workspace:
at: ~/workdir
- restore_cache:
key: yarn-cache-{{ checksum "yarn.lock" }}
- run:
name: Log environment setup
command: |
node -v
yarn -v
- run:
name: Install dependencies
command: yarn
- save_cache:
key: yarn-cache-{{ checksum "yarn.lock" }}
paths:
- /usr/local/share/.cache/yarn
- run:
name: Validate & Build
command: yarn run validate
- store_artifacts:
path: coverage
- store_test_results:
path: coverage
- run: yarn run coverage:push
- persist_to_workspace:
root: ~/workdir
paths:
- '*'
build-node-18:
<<: *build-stable
docker:
- image: node:18
build-node-16:
<<: *build-common
docker:
- image: node:16
tag_version:
docker:
- image: node:18
working_directory: ~/workdir
steps:
- attach_workspace:
at: ~/workdir
- run:
name: Configure Git
command: |
git config user.email "circleci@users.noreply.github.com"
git config user.name "CircleCI"
- run:
name: Tag version
command: |
git tag "$(cat .version)"
git push --tags "https://rtfpessoa:$GPR_AUTH_TOKEN@github.com/rtfpessoa/diff2html"
publish_library:
docker:
- image: node:18
working_directory: ~/workdir
steps:
- attach_workspace:
at: ~/workdir
- run:
name: Configure Yarn version
command: |
yarn config set version-tag-prefix ""
yarn config set version-git-message "Release version %s"
- run:
name: Configure Git
command: |
git config user.email "circleci@users.noreply.github.com"
git config user.name "CircleCI"
- run:
name: Version package
command: |
# Update version in packages to publish
yarn version --non-interactive --new-version $(cat .version)
- run:
name: Setup npm credentials
command: |
rm -f .npmrc
touch .npmrc
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc
echo "registry=https://registry.npmjs.org/" >> .npmrc
echo "access=public" >> .npmrc
echo "save-exact=true" >> .npmrc
- run:
name: Publish npm package
command: |
# Publish package versions to npmjs.org
yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version)
- run:
name: Setup gpr credentials
command: |
rm -f .npmrc
touch .npmrc
echo "//npm.pkg.github.com/:_authToken=${GPR_AUTH_TOKEN}" >> .npmrc
echo "@rtfpessoa:registry=https://npm.pkg.github.com/" >> .npmrc
echo "access=public" >> .npmrc
echo "save-exact=true" >> .npmrc
- run:
name: Publish gpr package
command: |
# HACK: Override npm package name to be able to publish in GitHub
sed -i 's/^ "name":.*/ "name": "@rtfpessoa\/diff2html",/g' package.json
echo "Going to publish version $(cat .version) to GitHub"
yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version)
# HACK: Restore npm package name
sed -i 's/^ "name":.*/ "name": "diff2html",/g' package.json
publish_website:
machine:
image: ubuntu-2204:current
working_directory: ~/workdir
steps:
- attach_workspace:
at: ~/workdir
- run:
name: Deploy
working_directory: ~/workdir/docs
command: |
aws s3 sync --region eu-west-1 --delete . s3://diff2html.xyz --metadata-directive REPLACE --cache-control max-age=31557600
aws cloudfront create-invalidation --region eu-west-1 --distribution-id $AWS_CF_DISTRIBUTION_ID --paths /index.html /demo.html /sitemap.xml /robots.txt
workflows:
validate-and-publish:
jobs:
- checkout-and-version
- build-node-16:
requires:
- checkout-and-version
- build-node-18:
requires:
- checkout-and-version
- publish_approval:
type: approval
requires:
- build-node-16
- build-node-18
- tag_version:
requires:
- publish_approval
- publish_library:
requires:
- tag_version
- publish_website:
requires:
- tag_version
filters:
branches:
only:
- master

12
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,12 @@
name: ci
on:
pull_request:
branches: [master]
jobs:
test-and-publish:
uses: ./.github/workflows/test-and-publish.yml
with:
environment: dev
secrets: inherit

View file

@ -1,51 +0,0 @@
name: "Code scanning - action"
on:
push:
pull_request:
schedule:
- cron: '0 19 * * 1'
jobs:
CodeQL-Build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

29
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,29 @@
name: release
on:
push:
branches: [master]
jobs:
test-and-publish:
uses: ./.github/workflows/test-and-publish.yml
with:
environment: production
secrets: inherit
publish-website:
runs-on: ubuntu-latest
container:
image: amazon/aws-cli
needs: [test-and-publish]
environment: 'production'
steps:
- name: Download docs
uses: actions/download-artifact@v3
with:
name: docs
- name: Publish to S3
run: |
cd docs
aws s3 sync --region eu-west-1 --delete . s3://diff2html.xyz --metadata-directive REPLACE --cache-control max-age=31557600
aws cloudfront create-invalidation --region eu-west-1 --distribution-id $AWS_CF_DISTRIBUTION_ID --paths /index.html /demo.html /sitemap.xml /robots.txt

148
.github/workflows/test-and-publish.yml vendored Normal file
View file

@ -0,0 +1,148 @@
name: test-and-publish
on:
workflow_call:
inputs:
environment:
required: true
type: string
jobs:
version:
runs-on: ubuntu-latest
container:
image: codacy/git-version
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fix tar access
run: apk add --update --no-progress tar
- name: Fix git access
run: |
git config --global --add safe.directory /__w/diff2html/diff2html
- name: Get next version
run: |
export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=master)"
echo "Next version is ${NEXT_VERSION}"
echo "${NEXT_VERSION}" > .version
- name: Get next npm tag name
run: |
if [ "${GITHUB_REF_NAME}" = "master" ]; then
export PUBLISH_TAG="latest"
elif [ "${GITHUB_REF_NAME}" = "next" ]; then
export PUBLISH_TAG="next"
else
export PUBLISH_TAG="pr"
fi
echo "Next tag is ${PUBLISH_TAG}"
echo "${PUBLISH_TAG}" > .tag
- name: Upload versions
uses: actions/upload-artifact@v3
with:
name: versions
if-no-files-found: error
path: |
.version
.tag
build:
runs-on: ubuntu-latest
needs: [version]
strategy:
matrix:
node-version: [16.x, 18.x]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Log environment setup
run: |
node -v
yarn -v
- name: Install dependencies
run: yarn install --ignore-engines
- name: Build templates
run: yarn run build:templates
- name: Build library
run: yarn run build
publish:
runs-on: ubuntu-latest
needs: [build]
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download versions
uses: actions/download-artifact@v3
with:
name: versions
- name: Configure Git
run: |
git config user.email "gh-actions@users.noreply.github.com"
git config user.name "GitHub Actions"
- name: Install dependencies
run: yarn
- uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
node-version: '18.x'
- name: Configure Yarn version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
rm -f .npmrc
touch .npmrc
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc
echo "registry=https://registry.npmjs.org/" >> .npmrc
echo "access=public" >> .npmrc
echo "save-exact=true" >> .npmrc
yarn config set version-tag-prefix ""
yarn config set version-git-message "Release version %s"
- name: Version package
run: |
# Update version in packages to publish
yarn version --non-interactive --new-version $(cat .version)
- name: Publish to NPM
run: yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version)
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com'
- name: Configure Yarn version
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
rm -f .npmrc
touch .npmrc
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc
echo "@rtfpessoa:registry=https://npm.pkg.github.com/" >> .npmrc
echo "access=public" >> .npmrc
echo "save-exact=true" >> .npmrc
yarn config set version-tag-prefix ""
yarn config set version-git-message "Release version %s"
- name: Version package
run: |
# Update version in packages to publish
yarn version --non-interactive --new-version $(cat .version)
- name: Publish to GPR
run: |
# HACK: Override npm package name to be able to publish in GitHub
sed -i 's/^ "name":.*/ "name": "@rtfpessoa\/diff2html",/g' package.json
echo "Going to publish version $(cat .version) to GitHub"
yarn publish --tag $(cat .tag) --non-interactive --new-version $(cat .version)
# HACK: Restore npm package name
sed -i 's/^ "name":.*/ "name": "diff2html",/g' package.json
- name: Upload docs
uses: actions/upload-artifact@v3
with:
name: docs
if-no-files-found: error
path: docs/