-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from HusseinKabbout/master
Add GitHub action to auto build production build
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: QWC2 Build | ||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- uses: actions/checkout@v2 | ||
- name: Checkout submodules | ||
shell: bash | ||
run: | | ||
auth_header="$(git config --local --get http.https://github.com/.extraheader)" | ||
git submodule sync --recursive | ||
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '10.x' | ||
|
||
- name: Install all required dependencies | ||
run: yarn install | ||
|
||
- name: Compile a deployable application bundle | ||
run: yarn run prod | ||
|
||
- name: Create zip | ||
run: zip -r qwc2-demo-app.zip prod/ | ||
|
||
- name: Version number | ||
id: version_number | ||
run: | | ||
if [ ${{ startsWith(github.ref, 'refs/tags/') }} = true ]; then | ||
VERSION=$(basename ${{ github.ref }}) | ||
else | ||
VERSION=ci-latest-$(basename ${{ github.ref }}) | ||
PREV_RELEASE=$(curl -s https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$VERSION | jq -r .url) | ||
# Reset ci-latest tag | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Github CI" | ||
# Workaround for "could not read Username for 'https://github.com': No such device or address" | ||
git remote set-url origin https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git | ||
git tag -d $VERSION || true | ||
git push origin :$VERSION || true | ||
git tag -m $VERSION $VERSION | ||
git push --tags | ||
fi | ||
echo "##[set-output name=version;]$VERSION" | ||
echo "##[set-output name=prev_release;]${PREV_RELEASE/null/}" | ||
env: | ||
# This token is provided by Actions, you do not need to create your own token. | ||
# The token is only valid for one hour. | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create release | ||
id: create_release | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ steps.version_number.outputs.version }} | ||
release_name: CI Build | ||
draft: false | ||
prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} | ||
|
||
- name: Upload release asset | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./qwc2-demo-app.zip | ||
asset_name: qwc2-demo-app.zip | ||
asset_content_type: application/zip | ||
|
||
- name: Delete previous release | ||
run: | | ||
curl -s -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-X DELETE ${{ steps.version_number.outputs.prev_release }} | ||
if: steps.version_number.outputs.prev_release != '' |