From fc927a241a962d3c0611eeff93549d780df2fe6a Mon Sep 17 00:00:00 2001 From: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:57:04 -0600 Subject: [PATCH] Add GitHub actions for CI and release --- .github/workflows/ci.yml | 53 +++++++++++++++++++++++++ .github/workflows/release.yml | 73 +++++++++++++++++++++++++++++++++++ Makefile.in | 6 +++ 3 files changed, 132 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7bf2a95 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,53 @@ +name: IBM i CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +env: + ssh_command: ssh ${{ secrets.IBMI_BUILD_USRPRF }}@${{ secrets.IBMI_BUILD_SYS }} + scp_dist_command: scp ${{ secrets.IBMI_BUILD_USRPRF }}@${{ secrets.IBMI_BUILD_SYS }}:/home/${{ secrets.IBMI_BUILD_USRPRF }}/build/${{ github.sha }}/dist.savf . + remote_build_dir: /home/${{ secrets.IBMI_BUILD_USRPRF }}/build/${{ github.sha }} + rsync_command: rsync -a --exclude='.*' --exclude='runners' --rsync-path=/QOpenSys/pkgs/bin/rsync ./ ${{ secrets.IBMI_BUILD_USRPRF }}@${{ secrets.IBMI_BUILD_SYS }}:/home/${{ secrets.IBMI_BUILD_USRPRF }}/build/${{ github.sha }}/ + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install private key + run: | + mkdir -p ~/.ssh + chmod 0755 ~ + chmod 0700 ~/.ssh + echo "${{ secrets.IBMI_BUILD_PVTKEY }}" > ~/.ssh/id_rsa + chmod 0600 ~/.ssh/id_rsa + - name: Disable strict host key checking + run: | + echo "Host *" > ~/.ssh/config + echo " StrictHostKeyChecking no" >> ~/.ssh/config + - name: Create build sandbox + run: $ssh_command "mkdir -p $remote_build_dir" + - name: Populate build sandbox + run: $rsync_command + - name: Get short SHA ID + run: | + echo "short_sha=$(echo ${{ github.sha }} | head -c 7)" >> $GITHUB_ENV + cat $GITHUB_ENV + - name: Get library name + run: | + echo "build_library=GH{{env.short_sha}}" >> $GITHUB_ENV + cat $GITHUB_ENV + - name: Perform remote build + run: $ssh_command "cd $remote_build_dir && /QOpenSys/pkgs/bin/python3.9 ./configure --library=$build_library && /QOpenSys/pkgs/bin/make clean dist" + - name: Retrieve artifact + run: $scp_dist_command + - name: Cleanup remote build lib + if: always() + run: $ssh_command "system 'dltlib $build_library'" + - name: Cleanup remote build dir + if: always() + run: $ssh_command "rm -fr $remote_build_dir" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dd0e95a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,73 @@ +name: IBM i build new release +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +env: + ssh_command: ssh ${{ secrets.IBMI_BUILD_USRPRF }}@${{ secrets.IBMI_BUILD_SYS }} + scp_dist_command: scp ${{ secrets.IBMI_BUILD_USRPRF }}@${{ secrets.IBMI_BUILD_SYS }}:/home/${{ secrets.IBMI_BUILD_USRPRF }}/build/${{ github.sha }}/dist.savf . + remote_build_dir: /home/${{ secrets.IBMI_BUILD_USRPRF }}/build/${{ github.sha }} + rsync_command: rsync -a --exclude='.*' --exclude='runners' --rsync-path=/QOpenSys/pkgs/bin/rsync ./ ${{ secrets.IBMI_BUILD_USRPRF }}@${{ secrets.IBMI_BUILD_SYS }}:/home/${{ secrets.IBMI_BUILD_USRPRF }}/build/${{ github.sha }}/ + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Install private key + run: | + mkdir -p ~/.ssh + chmod 0755 ~ + chmod 0700 ~/.ssh + echo "${{ secrets.IBMI_BUILD_PVTKEY }}" > ~/.ssh/id_rsa + chmod 0600 ~/.ssh/id_rsa + - name: Disable strict host key checking + run: | + echo "Host *" > ~/.ssh/config + echo " StrictHostKeyChecking no" >> ~/.ssh/config + - name: Create build sandbox + run: $ssh_command "mkdir -p $remote_build_dir" + - name: Populate build sandbox + run: $rsync_command + - name: Get short SHA ID + run: | + echo "short_sha=$(echo ${{ github.sha }} | head -c 7)" >> $GITHUB_ENV + cat $GITHUB_ENV + - name: Get library name + run: | + echo "build_library=GH{{env.short_sha}}" >> $GITHUB_ENV + cat $GITHUB_ENV + - name: Perform remote build + run: $ssh_command "cd $remote_build_dir && /QOpenSys/pkgs/bin/python3.9 ./configure --library=$build_library && /QOpenSys/pkgs/bin/make clean dist" + - name: Retrieve artifact + run: $scp_dist_command + - name: Cleanup remote build lib + if: always() + run: $ssh_command "system 'dltlib $build_library'" + - name: Cleanup remote build dir + if: always() + run: $ssh_command "rm -fr $remote_build_dir" + - name: Create the release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + - name: Upload *SAVF to release + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./dist.savf + asset_name: dist.savf + asset_content_type: application/zip \ No newline at end of file diff --git a/Makefile.in b/Makefile.in index 6a565da..a36548e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -124,3 +124,9 @@ xmlstoredp.srvpgm: qsrvsrc.srcpf $(XMLSTOREDP_MODULES) %.srcpf: $(LIBRARY).lib (system -q 'CHKOBJ $(LIBRARY)/$* *FILE' || system -q 'CRTSRCPF $(LIBRARY)/$*') && touch $@ +dist.savf: build + system "CRTSAVF ${LIBRARY}/dist" + system "SAVLIB LIB(${LIBRARY}) DEV(*SAVF) SAVF(${LIBRARY}/DIST)" + cp /qsys.lib/${LIBRARY}.lib/dist.file ./dist.savf + +dist: dist.savf \ No newline at end of file