--- #464
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: [create, pull_request, push] | |
env: | |
IMAGE_ID: herve76/node-binance-trader | |
jobs: | |
docker: | |
name: Docker | |
runs-on: ubuntu-latest | |
steps: | |
- name: Git checkout | |
uses: actions/[email protected] | |
- name: Docker Buildx setup | |
id: buildx | |
uses: docker/[email protected] | |
- name: Registry login | |
if: github.event_name != 'pull_request' | |
run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USER_NAME }}" --password-stdin | |
- name: Build | |
run: | | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "master" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
# Push the Docker image to the registry on git pushes that either pushed a tag or one of the following branches: [master, testing] | |
if [[ | |
( | |
"${{ github.event_name }}" == "create" | |
&& | |
${{ startsWith(github.ref, 'refs/tags/') }} == "true" | |
) | |
|| | |
( | |
"${{ github.event_name }}" == "push" | |
&& | |
${{ startsWith(github.ref, 'refs/heads/') }} == "true" | |
&& | |
( | |
$VERSION == "latest" | |
|| | |
$VERSION == "testing" | |
) | |
) | |
]] | |
then | |
docker buildx build \ | |
--cache-from=$IMAGE_ID:cache \ | |
--cache-to=$IMAGE_ID:cache \ | |
--push \ | |
-t $IMAGE_ID:$VERSION \ | |
. | |
else | |
docker buildx build \ | |
--cache-from=$IMAGE_ID:cache \ | |
-t $IMAGE_ID:$VERSION \ | |
. | |
fi | |
semantic-release: | |
if: github.event_name != 'pull_request' | |
name: Semantic Release | |
runs-on: ubuntu-latest | |
needs: docker | |
steps: | |
- uses: actions/[email protected] | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Semantic Release | |
uses: cycjimmy/[email protected] | |
with: | |
extra_plugins: | | |
@semantic-release/changelog | |
@semantic-release/git | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release-assets: | |
if: startsWith(github.ref, 'refs/tags/') | |
name: Release Assets | |
runs-on: ubuntu-latest | |
needs: semantic-release | |
steps: | |
- name: Git checkout | |
uses: actions/[email protected] | |
- name: Docker Buildx setup | |
id: buildx | |
uses: docker/[email protected] | |
- name: Build "build" | |
run: | | |
docker buildx build \ | |
--cache-from=$IMAGE_ID:cache \ | |
-t stage_build \ | |
--target build \ | |
--load \ | |
. | |
docker container create --name extract stage_build | |
docker container cp extract:/srv/app/ ./ | |
docker container rm -f extract | |
- name: Zip | |
uses: montudor/[email protected] | |
with: | |
args: zip -qq -r ./nbt.zip ./ | |
- name: GitHub Release Asset | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: nbt.zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |