diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml index 95b8133..e15c224 100644 --- a/.github/workflows/blank.yml +++ b/.github/workflows/blank.yml @@ -2,13 +2,14 @@ name: CI -# Controls when the action will run. +# Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the main branch push: - branches: [ main ] + tags: + - "v*" pull_request: - branches: [ main ] + branches: [main, zip-and-release] # Allows you to run this workflow manually from the Actions tab # workflow_dispatch: @@ -25,16 +26,49 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! - # Runs a set of commands using the runners shell - name: Run a multi-line script run: | echo Add other actions to build, echo test, and deploy your project - - name: Tag + - name: Pack + id: pack + run: | + echo ::set-output name=ZIP_FILE_NAME::$(npm run pack | awk '{if( $1 ~ "output_" ) print $1}') + + - name: Get the version + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} + + - name: Get commit summary + id: get_commit_summary run: | - git tag -a v0.0.1 -m "version 0.0.1" - git push origin --tags + PREVIOUS_TAG=$(git tag --sort=-creatordate | sed -n 2p) + echo "PREVIOUS_TAG: $PREVIOUS_TAG" + COMMIT_SUMMARY="$(git log --oneline --pretty=tformat:"%h %s" $PREVIOUS_TAG..${{ github.ref }})" + COMMIT_SUMMARY="${COMMIT_SUMMARY//$'\n'/'%0A'}" + echo ::set-output name=COMMIT_SUMMARY::$COMMIT_SUMMARY + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.get_version.outputs.VERSION }} + release_name: Release ${{ steps.get_version.outputs.VERSION }} + body: | + ${{ steps.get_commit_summary.outputs.COMMIT_SUMMARY }} + draft: false + prerelease: false + + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./${{ steps.pack.outputs.ZIP_FILE_NAME }} + asset_name: ${{ steps.pack.outputs.ZIP_FILE_NAME }} + asset_content_type: application/zip diff --git a/package.json b/package.json new file mode 100644 index 0000000..e2d724d --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "github_actions_training", + "version": "1.0.0", + "description": "![CI](https://github.com/utakeru/github_actions_training/workflows/CI/badge.svg)", + "main": "index.js", + "scripts": { + "pack": "FILENAME=output_$npm_package_version.zip && zip $FILENAME zipTarget.txt && echo $FILENAME", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/utakeru/github_actions_training.git" + }, + "author": "utakeru", + "license": "MIT", + "bugs": { + "url": "https://github.com/utakeru/github_actions_training/issues" + }, + "homepage": "https://github.com/utakeru/github_actions_training#readme" +} diff --git a/zipTarget.txt b/zipTarget.txt new file mode 100644 index 0000000..d0513b2 --- /dev/null +++ b/zipTarget.txt @@ -0,0 +1 @@ +zip