0

I am working on configuring a deployment pipeline for my team. We are using Github Actions and I have most of it sorted, but ran into an issue when trying to run certain steps in a sequential order.

The app is ASP.NET Core MVC with some Blazor support. We are using webpack, webpack-cli css-loader & style-loader to bundle and minify our CSS and JS files.

The issue: I need to be able to run the npm build task before the .net core publish task in github actions. I am able to get the steps to run sequentially HOWEVER, the files generated in step 1 (the npm build) don't seem to be available to the .net core publish actions which happens after.

Question: what do I need to do in order to have the newly generated npm build files be used by the .net core publish action? I assume its a matter of moving them around to the correct location, however I am having trouble finding any good info on this. I have done Much trial and error, and research has been unfruitful.

Below is the yaml file and webpack file being used, and the command run is just npm run build

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .net Publish

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:      
  job1:
    runs-on: ubuntu-latest    
    strategy:
      matrix:
        node-version: [15.x]
    steps:
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
          node-version: ${{ matrix.node-version }}        
    - name: build webpack
      uses: actions/checkout@v1      
    - run: ls -a
    - run: npm i
      working-directory: ./ClientApp    
    - run: npm run build    
      working-directory: ./ClientApp        
    - run: pwd
    - run: ls -a
    - name: Persist npm build output
      uses: actions/upload-artifact@v3
      with:
        name: npm-post-build
        path: | 
          ./wwwroot/dist/**
  job2:
    needs: job1
    runs-on: ubuntu-latest    
    steps:    
    - name: Install Octopus Deploy CLI
      uses: OctopusDeploy/install-octopus-cli-action@v1
      with:
        version: '*'
    - uses: actions/checkout@v3
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 7.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: replace dist with npm build artifact
      uses: actions/download-artifact@v3
      with: 
        name: npm-post-build
        path: npm-post-build
    - shell: bash
      run: |
        ls -a
        rm -r wwwroot/dist
        ls wwwroot
        mv npm-post-build wwwroot/dist
        ls wwwroot/dist
    - name: Build
      run: dotnet build --no-restore   
    - name: Publish
      run: dotnet publish -p:PublishProfile=FolderProfile -o website    
    - name: package
      run: |
          shopt -s globstar
            paths=()
            for i in website/**; do
              dir=${i%/*}
              echo ${dir}
              paths=(${paths[@]} ${dir})
            done
            eval uniquepaths=($(printf "%s\n" "${paths[@]}" | sort -u))
            for i in "${uniquepaths[@]}"; do
              echo $i
            done        
            packages=()
            versions=()            
            for path in "${uniquepaths[@]}"; do
              dir=${path}/../../../..
              parentdir=$(builtin cd $dir; pwd)
              projectname=${parentdir##*/}          
              octo pack \
              --basePath ${path} \
              --id ${projectname} \
              --version 1.0.0 \
              --format zip \
              --overwrite
              packages=(${packages[@]} "${projectname}.1.0.0.zip")
              versions=(${versions[@]} "${projectname}:1.0.0")
            done
        
            printf -v joined "%s," "${packages[@]}"
            echo "::set-output name=artifacts::${joined%,}"
            printf -v versionsjoinednewline "%s\n" "${versions[@]}"
            versionsjoinednewline="${versionsjoinednewline//'%'/'%25'}"
            versionsjoinednewline="${versionsjoinednewline//$'\n'/'%0A'}"
            versionsjoinednewline="${versionsjoinednewline//$'\r'/'%0D'}"
            echo "::set-output name=versions_new_line::${versionsjoinednewline%\n}"
            echo "prepackage complete ${packages}"            
    - name: Push a package to Octopus Deploy
      uses: OctopusDeploy/push-package-action@v3
      env:
            OCTOPUS_URL: https://****.octopus.app/
            OCTOPUS_API_KEY: *****
            OCTOPUS_SPACE: 'Default'
      with:
            overwrite_mode: OverwriteExisting
            packages:  runner.1.0.0.zip
    
    
const path = require('path');

module.exports = {
    entry: {
        site: '../wwwroot/js/site.js'
    },
    output: {
        filename: '[name].entry.js',
        path: path.resolve(__dirname, '..', 'wwwroot', 'dist')
    },
    devtool: 'source-map',
    mode: 'development',
    module: {
        rules: [
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader'],
            },
            {
                test: /\.(eot|woff(2)?|ttf|otf|svg)$/i,
                type: 'asset'
            },
        ]
    }
};
d0rf47
  • 409
  • 8
  • 20
  • The steps of a job are always run sequentially. It's the jobs that run concurrently and may need to be configured with `needs` to specify the dependence on other jobs. Jobs run on different runners and the files won't be available for other jobs as they are in the case of steps. As you already need to make this sequential, you can simply remove the second job and add it to the steps of the same job. The files will be available and you can publish them from there. – Azeem Feb 09 '23 at 16:50
  • Yeah so I was actually able to generate an artifact save it and retrieve it, and replaced the desired files, but for some reason they still are not being used in final published application :/ i will update the above yaml file to show the changes – d0rf47 Feb 09 '23 at 17:10
  • Yes, artifacts could be used or cache may also be used. But, IMHO, that'll complicate your workflow. You need dependence on build for publishing so it's much better to combine those instead of handling it any other way. – Azeem Feb 09 '23 at 17:14
  • Yeah I understand that but i am trying to learn the github actions better with this, I just don't understand why i can download the files and run a directory removal and then move the files to where i need them, I can see that the replacement worked via ls command. But it makes me wonder if the dotnet publish commands are pulling the files from somewhere else then – d0rf47 Feb 09 '23 at 17:19

0 Answers0